What will be the output of following program? #include <stdio.h> int main() {…
What will be the output of following program?
#include <stdio.h>
int main() {
char s1[7] = "abcd";
char *p;
p = s1 + 2;
*p = 'e';
printf("%s", s1);
return 0;
}
Answer: C. abed — Answer: C) abed Explanation: Initial String: s1 stores the string "abcd". Pointer Setup: p = s1 + 2; makes the pointer p point directly to the third character…
- A.
abcde
- B.
abd
- C.
abed
- D.
abcd0e
Attempted by 178 students.
Show answer & explanation
Correct answer: C
Answer: C) abed
Explanation:
Initial String:
s1stores the string"abcd".Pointer Setup:
p = s1 + 2;makes the pointerppoint directly to the third character in the string, which is'c'(at index 2).Modification:
*p = 'e';modifies the value at that exact memory location, overwriting'c'with'e'.
Consequently, the string changes from "abcd" to abed.