Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program ?

#include <stdio.h>

int main()
{
    char str[7] = "IndiaBIX";
    printf("%s\n", str);
    return 0;
}

 

  • A.Error
  • B.IndiaBIX
  • C.Cannot predict
  • D.None of above

Answer: C

Correct answer: Cannot predict

The initialiser needs nine bytes - eight characters and a null - but the array has only seven. A compiler will warn, and where it accepts the code it truncates, leaving IndiaB with no terminating null. Printing that runs past the end of the array, so what appears depends on whatever bytes follow.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.