CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
4
You visited us 4 times! Enjoying our articles? Unlock Full Access!
Question

What is the output of the following program?
# include <stdio.h>
int main ( )
{
int x = 5;
int * const ptr = &x;
++(*ptr)
printf("%d", x);
return 0;
}


A
6
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
5
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Runtime Error
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Compiler Error
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A 6
See following declarations to know the difference between constant pointer and a pointer to a constant.
int* constptr ptr is constant pointer. You can change the value at the location pointed by pointer p, but you cannot change p to point to other location.

int const * ptr ptr is a pointer to a constant. You can change ptr to point other variable. But you cannot change the value pointed by ptr.
Therefore above program works well because we have a constant pointer and we are not changing ptr to point to any other location.
We are only incrementing value pointed by ptr.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Heat Capacity
CHEMISTRY
Watch in App
Join BYJU'S Learning Program
CrossIcon