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;
}
Mello
Hello
HMello
MHello
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
69 comments Page 6 of 7.

M.Bhagya said:   1 decade ago
Here p contains the base address and that value H is replaced by M.

Sharad salve said:   1 decade ago
Here p contains the base address and that value H is replaced by M.

Swetha sathish k said:   1 decade ago
char *const p means p pointer is a constant. but the array is not.

Dragon said:   1 decade ago
If we put *p=bye then answer is eello.

Can any one explain how?

Rishikesh said:   9 years ago
String name itself indicates base adress for first character.

Nithya said:   1 decade ago
How to replace the second letter of the word "hello" by m ?

TDas said:   5 years ago
*p=*p[0]='M' and rest of the character should be as it is.
(1)

MOUNICA said:   7 years ago
Please give the detailed description for getting this.
(2)

Dharmesh said:   1 decade ago
How can we change the value constant pointer ?

Swetha sathish k said:   1 decade ago
Here pointer is constant, but not the string.


Post your comments here:

Your comments will be displayed after verification.