Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 17 - 19 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 17

C & C Plus Plus
Edit

Write in Short

What is the output of the following program?

1. voidmain ()
2. {
3.     inti =i ++, j =j ++, k =k ++;
4.     printf (%d%d%d, i, j, k);
5. }

Explanation

In the program an identifier is available to use in program code from the point of its declaration.

 int i = i ++ , j = j ++ , k = k ++ ; Expressions such as i = i ++ are valid statements.The i, j and k are automatic variables and so they contain some garbage values printf (% d % d % d, i, j, k) ; So, the printf prints garbage value of i, j and k.

Question 18

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following?

inti; i=1; i=i+2i++; printf(“%d”,i);

Explanation

• In the program
 int i; define the integer variable i i = 1; Here integer variable i is assigned the value of 1 i = i + 2 ⚹ i ++ ; here i = i + 2 ⚹ i ++ ;i = 1 + 2 ⚹ 1 ++i = 3 ⚹ 1 ++i = 3 ++i = 4 printf ( “% d” , i) ; printf prints the value of i is 4

Question 19

C & C Plus Plus
Edit

Describe in Detail

Essay▾
1. #defineone0
2. #ifdefone
3. printf ( “oneisdefined” );
4. #endif
5. #ifndefone
6. printf ( “oneisnotdefined” );
7. #endif

Explanation

• In the program ifdef means “if the following is defined” while ifndef means “if the following is not defined” .
 #define one 0 Here one is defined #ifdef oneprintf ( “one is defined” ) ;#endif Check the one is defined or not.Since one is defined so the ifdef is true and the ifndef is false.So printf prints “one is defined” .

Developed by: