Computer Sciences > GATE 2025 SET-2 > C Programming
Consider the following C program:
Which ONE of the following will be the output of the program?
A
#Hello World!
B
Hello World!
C
ello World!
D
Hello World!d!

Correct : c

The correct answer is Option C — ello World!
The C program uses strchr to locate the first occurrence of a character in the string "Hello World!", then advances the pointer by 1 position past that character. The resulting pointer now points to the substring starting one character after ''H'' — which is "ello World!".
When this pointer is passed to printf or puts, it prints from that position to the end of the string, giving the output ello World! — note the capital ''H'' is skipped.
This is a classic pointer arithmetic question in C. strchr returns a pointer into the original string, and adding 1 to it simply moves one character forward without creating a new string.

Similar Questions

Consider the following two functions void fun1(int n){     if(n == 0) return;       printf(“%d”, n);     fun2(n-2); &...
#175 MCQ
Consider the C functions foo and bar given below: int foo(int val) {     int x = 0;     while (val > 0)     {     &nbs...
#190 MCQ
What is printed by the following ANSI C program? #include<stdio.h> int main(int argc, char *argv[]) {     int a[3][3][3] =     {{...
#311 MCQ

Related Topics

C program output GATE 2025 GATE CS 2025 Set-2 Q19 strchr C function GATE puts printf output C C string pointer GATE ello World C output C programming GATE 2025 string offset pointer C GATE computer science C language GATE previous year questions

Unique Visitor Count

Total Unique Visitors

Loading......