Home / C Programming / Strings :: Discussion

Discussion :: Strings

  1. What will be the output of the program ?

     #include
     #include 
    
     int main() 
     {   
        char str[] = "Fresher\0\GATE\0";     
        printf("%s\n", str);  
        return 0; 
     } 
    

  2. A.

    GATE

    B.

    Fresher

    C.

    Fresher GATE

    D.

    Fresher\0GATE

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    A string is a collection of characters terminated by '\0'.

    Step 1: char str[] = "Fresher\0\GATE\0"; The variable str is declared as an array of characters and initialized with value "Fresher"

    Step 2: printf("%s\n", str); It prints the value of the str.

    The output of the program is "Fresher".


Be The First To Comment