Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 154 - 156 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 154

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Is this code legal?

int ⚹ ptr;

ptr = (int ⚹) 0 × 400;

Explanation

  • In these code
Table Showing the Code
int ⚹ ptr;
  • Define the integer pointer ptr.
ptr = (int ⚹) 0 × 400;
  • The pointer ptr will point at the integer in the memory location 0 × 400

Question 155

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inti =5, j =10;
  4.     i =i& =j&&10;
  5.     printf ( “%d %d”, i, j);
  6. }

Explanation

In the program

Table Shows the Program
int i = 5, j = 10;
  • Given the integer variable i = 5 and j = 10
i = i& = j&&10;
  • The expression can be written as i = (i& = (j&&10) ) ;
  • The inner expression (j&&10) evaluates to 1 because j == 10 and i is 5. i = 5&1 is 1.
printf ( “% d % d” , i, j) ;
  • Print the value of i and j- 1 and 10.

Question 156

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Predict the output or error (s) for the following:

  1. main ()
  2. {
  3.     inti =257;
  4.     int ⚹iPtr =&i;
  5.     printf ( “%d,%d” ,⚹((char⚹)iPtr),⚹((char⚹) iPtr+1));
  6. }

Explanation

In the program

Table Shows the Program
int i = 257;
  • Given the integer variable i = 257
int ⚹ iPtr = &i;
  • The integer value 257 is stored in the memory as , 00000001 00000001
printf ( “% d, % d” , ⚹ ( (char ⚹) iPtr) , ⚹ ( (char ⚹) iPtr + 1) ) ;
  • So the individual bytes taken by casting it to char ⚹ get printed as 1,1

Developed by: