Home / C Programming / Library Functions :: Discussion

Discussion :: Library Functions

  1. Will the program outputs "IndiaBIX.com"?

     #include
     #include 
    
      int main() 
      {    
         char str1[] = "fresherGATE.com";      
         char str2[20]; 
         strncpy(str2, str1, 8);     
         printf("%s", str2); 
         return 0; 
     }  
    

  2. A.

    Yes

    B.

    No

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    No. It will print something like 'IndiaBIX(some garbage values here)' .

    Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with IndiaBIX.


Be The First To Comment