Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Sunday, 4 July 2021

Interview Hack#37 Answer

 What will be the output of the program?

  1. Error
  2. H
  3. Hello
  4. Hel
  5. None Of the Above

Correct answer 3)Hello

Explanation:

Step 1: const char *s = ""; The constant variable s is declared as a 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 characters type and initialized with a string "Hello".

Step 3: s = str; The value of the variable str is assigned to the variable s. Therefore str contains 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.

Hence the output of the program is "Hello".

0 comments:

Post a Comment