Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



What is the output of the following code snippet?  
#include <stdio.h>
main() {
int x = 65, *p = &x;
void *q = p;
char *r = q;
printf("%c", *r);
}

(A) $A$  
(B) $Z$  
(C) $65$  
(D) None of the above  





Solution

Step 1: Initialization

$x = 65$
In ASCII, $65 \equiv A$

Step 2: Pointer flow
$p = \&x \;\; \rightarrow$ pointer to integer
$q = p \;\; \rightarrow$ void pointer
$r = q \;\; \rightarrow$ typecast to char pointer

Step 3: Dereferencing
Since r is char*, it reads 1 byte.
The value stored = $65$

Step 4: Printing
printf("%c", *r); prints character with ASCII $65$.
Hence, the output is:

$\; \boxed{A} \;$

Correct Answer: (A) 



Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...