Sail E0 Webinar
Question


What will be the output of the program?


#include<stdio.h>
int main()
{
const char *s = "";
char str[] = "Hello";
s = str;
while(*s)
printf("%c", *s++);
return 0;
}
Options:
A .  Error
B .  H
C .  Hello
D .  Hel
Answer: Option C

Step 1: const char *s = ""; The constant variable s is declared as an pointer to an array of 

characters type and initialized with an empty string.

Step 2: char str[] = "Hello"; The variable str is declared as an array of charactrers type and 

initialized with a string "Hello".

Step 3: s = str; The value of the variable str is assigned to the variable s. Therefore strcontains 

the text "Hello".

Step 4: while(*s){ printf("%c", *s++); } Here the while loop got executed untill the value of the 

variable s is available and it prints the each character of the variable s. and it prints the each 

character of the variable s.

Hence the output of the program is "Hello".




Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers