Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the statements is correct about the program?

#include <stdio.h>

int main()
{
    int i=10;
    int *j=&i;
    return 0;
}

 

  • A.j and i are pointers to an int
  • B.i is a pointer to an int and stores address of j
  • C.j is a pointer to an int and stores address of i
  • D.j is a pointer to a pointer to an int and stores address of i

Answer: C

Correct answer: j is a pointer to an int and stores address of i

The declaration int *j = &i; declares j as a pointer to int and initialises it with the address of i.

The asterisk belongs to the declarator, not to the type specifier - the declaration reads "*j is an int", hence j is a pointer to int. i is an ordinary int and no pointer at all, and j has one level of indirection, not two, which the number of asterisks makes plain.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.