HELP with all these The C++ preprocessor directive #include is most like which C
ID: 2246397 • Letter: H
Question
HELP with all these
The C++ preprocessor directive #include is most like which C preprocessor directive? Why is each #include included? What is the purpose for this using directive? using namespace std: Translate each of the following C statements into its C++ equivalent. Assume using namespace std: is coded in the program so you are not required to scope-resolve references to the stream variables cin and cout. Describe/Define each of the 3 tokens used to code the scope-resolved reference the stream variable cout, namely, std:: cout. std:: cout Make the following 2-line sentences into C++ comments using appropriate C++ comment-building syntax. Make these 2 lines a single 2-line C++ comment. Make these 2 lines 2 1-line C++ comments. Evaluate the bool expression (true || false && false || ! false)Explanation / Answer
Please find below the answer with expalnation :
1.) The C++ preprocessor directive #include<iostream> is most likely
with #include<stdio.h> preprocessor in C. It is used for input and output.
In C++ can use cin and cout and in C scanf and printf for input/output.
2.)purpose of directive using namespace std
in C++ library or can say header files there are many functions with same name in another modules/header files.
when will call in program without namespace conflict get occours and Compiler complains about the same.
std is the defined namespace in which most functions are written like cin,cout,string ..etc.
so in order to distinguish the method we use namespace.
3.)int x,y; ---> int x,y; //(work in c++ also)
4.)printf("%d %d ",x,y); ---> cout<<x<<" "<<y<<endl;
5.)scanf("%d%d",&x,&y); ---> cin>>x;cin>>y;
6.)x-=y+2 ---> x-=y+2 //(work in c++ also)//euivalent to x = x - (y+2)
7.) if((x % 2 == 1)||(y >= 0))
{
y++,x/=2;
}
--->
if((x % 2 == 1)||(y >= 0))//(work in c++)
{
y++,x/=2;
}
//or
if((x % 2 == 1)||(y >= 0))//(works fine in c++)
{
y++;
x=x/2;
}
8.)std::cout
std -> it is the name of namespace.
::-> it directs code to use global scope instead of local scope it is alos known as scope resolution operator
cout-> it is stream in c++ for displaying the output.
9.)// used in c++ for single line comment
and /*lines*/ for combining the comment in one line
//Make these 2 lines a single 2 -line
//c++ comment.
/*Make these 2 lines 2 1 -line
c++ comment.*/
10.)(true || false && false && false || !false)
false && false -->will be true so can write as below
(true || true && false || !false)
false || !false --> will be equivalent to true because !false it true. now its look below
(true || true && true)
true && true --> will be result in true , now it will be as per below,
(true || true) --> it is true
so bool expression (true || false && false && false || !false) is evaliated to true
//Please do let me know if u have any doubts..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.