C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 4)
4.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char str[20] = "Hello";
char *const p=str;
*p='M';
printf("%s\n", str);
return 0;
}
Discussion:
69 comments Page 6 of 7.
Sudhakar said:
1 decade ago
Here pointer is a constant type so the add stored by this can't be changed but we can change the value.
Sandeep kumar said:
1 decade ago
Thnx guys really helpful. But I want to ask what is the difference between
char *const p;
and
char const *p;.
char *const p;
and
char const *p;.
Saurav said:
1 decade ago
P is const how can we change it?
Pruthvi said:
1 decade ago
If p is a pointer to a character constant then how can the character constant value can be changed?
Rocketraja said:
1 decade ago
Can you explain still more clearly?
Saroj said:
1 decade ago
If we declare the constant pointer then already declared place is in array a[size], what ever we declare that place depends on the size it should changed.
Biswajit said:
1 decade ago
[H][e][l][l][o][w]
10 11 12 13 14 15 (Assume these are address of memory)
here,str=10
char*const p=str (here,p will store 10 that is constant)
so,now *p indicate "H" that has replaced by "M"
note: Base address also is a pointer & constant.
10 11 12 13 14 15 (Assume these are address of memory)
here,str=10
char*const p=str (here,p will store 10 that is constant)
so,now *p indicate "H" that has replaced by "M"
note: Base address also is a pointer & constant.
Dharmesh said:
1 decade ago
How can we change the value constant pointer ?
Vivekmk said:
1 decade ago
*p denote the value in the base address so *p="M" will replace the character at base that is it will replace "H" so Mello
Bijan said:
1 decade ago
Any one can explain second line
char *const p=str;
Or output of second line
char *const p=str;
Or output of second line
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers