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

Discussion

In C Programming, If we need to store word "INDIA" then syntax is as below -

  • A.char name[6] = {'I','N','D','I','A','\0'}
  • B.char name[6] = {"I","N","D","I","A"}
  • C.
    char name[];
    name = "INDIA"
  • D.char name[6] = {'I','N','D','I','A'}

Answer: A

Correct answer: char name[6] = {'I','N','D','I','A','\0'}

A C string is a character array ending in a terminating null, so “INDIA” needs six cells: five letters and '\0'. Single quotes make characters; double quotes would make five separate strings. And an array cannot be assigned to after declaration, so name = "INDIA"; is not valid either. (char name[6] = "INDIA"; would also work - the compiler supplies the null.)

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

Post your comment

Please log in or register to post a comment.