What will be the output? int main() { char *ptr = "knowledgegate";…

What will be the output?

int main()

{

char *ptr = "knowledgegate";

printf("%c\n", *&*&*ptr);

return 0;

}

Answer: D. kConcept: The unary operators * (dereference) and & (address-of) are exact inverses of each other. In C, unary operators are right-associative, so a chain like…

  1. A.

    Compiler Error

  2. B.

    Garbage Value

  3. C.

    Runtime Error

  4. D.

    k

Attempted by 328 students.

Show answer & explanation

Correct answer: D

Concept: The unary operators * (dereference) and & (address-of) are exact inverses of each other. In C, unary operators are right-associative, so a chain like *&*&*ptr is grouped as *(&(*(&(*ptr)))) — each adjacent &* or *& pair cancels, and printf's %c conversion always prints exactly one character, never a string, however deep the pointer chain.

Applying it here:

  1. ptr is a char* initialized to the string literal "knowledgegate", so ptr points to its first character, 'k'.

  2. *ptr dereferences ptr and yields the char 'k'.

  3. &*ptr takes the address of that char — this is the same address as ptr itself.

  4. *&*ptr dereferences that address again, giving back 'k'.

  5. &*&*ptr takes the address once more (same address as ptr).

  6. *&*&*ptr dereferences a final time, yielding 'k' — the value printed by %c.

Why not the full string: This chain never touches any character beyond the first: *ptr always yields a single char, not the string, so no number of alternating & and * operations can make it produce "knowledgegate" — printing the whole string would need %s with ptr itself (not a dereferenced char), e.g. printf("%s", ptr).

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…