Output of C programs | Set 64 (Pointers)

Prerequisite : Pointers in C
Question 1 : What will be the output of following program?

OPTIONS:
a)C B
b)B A
c)B C
d)C A

OUTPUT: (d) C A

Explanation:
Line 1 : Now, ppp points to next memory location i.e., index 1 of the character array.
Line 2 : Firstly, –*ppp= –(*ppp) is executed and hence the value ‘B’ (which is in the index 1 position of the char[] array) gets decremented by 1(i.e., it becomes ‘A’)and it is sent for printing. Then *++ppp= *(++ppp) is executed which initially increments the pointer to the next element of the array and prints the value in that index number 2 which is ‘C’. Although –*ppp is executed first compared to *++ppp, the display will be shown in the order as we mentioned in the printf() function in line 2. Hence we get output as C A.

Question 2 : What will be the output of following program?

OPTIONS:
a) compilation error
b) Runtime error
c) 5
d) linker error

OUTPUT: (b) Runtime error

Explanation: Pointer variable (*ptr) cannot be initialized.

Question 3 : What will be the output of following program?

OPTIONS:
a) Address Value
b) Value Address
c) Address Address
d) Compilation error

OUTPUT: (c)Address Address

Explanation: & and * cancelled each other and display the address stored in a pointer variable ptr i.e) the address of a.

Question 4 : What will be the output of following program?

OPTIONS:
a) Compilation error
b) num = 10 address of num = 2293436
num = 11 address of num = 2293438
c) num = 10 address of num = 2293436
num = 11 address of num = 2293440
d) num = 10 address of num = 2293436
num = 11 address of num = 2293436

OUTPUT: (d)

Explanation: Here a variable num holds the value 10 and get its address as 2293436, then increment is done as num++ which uses the same address space to store the incremented value.

Question 5 : What will be the output of following program?

OPTIONS:
a) address address value
b) address value value
c) address address address
d) compilation error

OUTPUT : (a)address address value

Explanation : Here a pointer variable *j hold the address of i and then another pointer variable *k hold the address of j.
now
k = address of j
*k = address of i
**k = value of i.

This article is contributed by Abhishek kurmi.



My Personal Notes arrow_drop_up

Recommended Posts:


    Article Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.