C Programming - Const - Discussion
Discussion Forum : Const - Find Output of Program (Q.No. 5)
5.
What will be the output of the program in TurboC?
#include<stdio.h>
int fun(int **ptr);
int main()
{
int i=10, j=20;
const int *ptr = &i;
printf(" i = %5X", ptr);
printf(" ptr = %d", *ptr);
ptr = &j;
printf(" j = %5X", ptr);
printf(" ptr = %d", *ptr);
return 0;
}
Discussion:
28 comments Page 2 of 3.
Vineet Yadav said:
1 decade ago
const int *ptr;
int const* ptr;
It means pointer points to const integer value. that means we cant change the value of that integer but pointer can change its pointing location.
int * const ptr;
const * int ptr;
It means that pointer is constant here, it can point to an integer and then it cant change its pointing location.
int const* ptr;
It means pointer points to const integer value. that means we cant change the value of that integer but pointer can change its pointing location.
int * const ptr;
const * int ptr;
It means that pointer is constant here, it can point to an integer and then it cant change its pointing location.
ChaZ said:
1 decade ago
Simplifying the above explanation,
const int *ptr //cannot modify *ptr
int* const ptr //cannot modify ptr
Difference in ptr and *ptr is self-explanatory.
const int *ptr //cannot modify *ptr
int* const ptr //cannot modify ptr
Difference in ptr and *ptr is self-explanatory.
Ritesh lenka said:
1 decade ago
Here the int value that pointed by ptr is const. Not the ptr. When we declare int const *ptr, then ptr is consider as a constant.
Akshay11 said:
1 decade ago
What does %5x means?
Abhishek said:
1 decade ago
Can't understand? please explain?
Varinder said:
1 decade ago
How constant may change?
Debasisd16061 said:
1 decade ago
What is %5x?
Surbhi said:
1 decade ago
% 5x here x is for hexadecimal value of ptr that has assigned to I and 5 specifies the width of ptr at least 5 digits wide (space also included).
Suyog said:
9 years ago
Please, can anybody explain it detail?
Bhavani said:
9 years ago
How FFE4 and FFE2 came in output? Please explain me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers