Multiple choice technology programming languages

main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

  1. 3 4 6 5 2 2 2 2 2 2

  2. 4 6 5 2 2 2 2 2 2 3

  3. 2 2 2 3 4 6 5 2 2 2

  4. 2 2 2 2 2 2 3 4 6 5

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The array c is initialized with float values that are truncated to integers: {2, 3, 4, 6, 5}. The first loop prints *c (which is c[0], i.e., 2) five times, outputting ' 2 2 2 2 2 '. The second loop prints the dereferenced pointer p (which starts at c and increments), outputting the individual elements ' 2 3 4 6 5 ' sequentially. Combined, this outputs ' 2 2 2 2 2 2 3 4 6 5 '.