Aspire Faculty ID #12632 · Topic: JECA MCA 2024 · Just now
JECA MCA 2024

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) 

Next 10 Questions — JECA MCA 2024

Ascending by ID
Ask Your Question or Put Your Review.

loading...