Const - Find Output of Program :: Discussion


6.What will be the output of the program?
A.Error
B.H
C.Hello
D.He
Answer:  Option  C
Explanation:

Step 1const char *s = ""; The constant variable s is declared as an pointer to an array of characters type and initialized with an empty string.

Step 2char str[] = "Hello"; The variable str is declared as an array of charactrers type and initialized with a string "Hello".

Step 3s = str; The value of the variable str is assigned to the variable s. Therefore str contains the text "Hello".

Step 4while(*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".

Tutorial Link:
Published by:Michael Daani

Comments are not available

Post your comments here:

Optional

Date to Date Current Affairs 2022

PakMCQs.net

Quick Links

GAT Subject



   Computer Science    English Mcqs    Agriculture    

Engineering



   Computer Science    Civil Engineering    

Technical



   Networking    Electronics    Database    

Past Papers



   Model Papers    FPSC Papers