Character Array MCQ 3 : String Cannot be Assigned to Array Variable at Run Time



Character Array MCQ 3 : String Assigned to Character Array


Predict the Output of the Following Program ?

#include<stdio.h>

void main()
{
char str[]="Learn C";
char *sptr="Learn Java";

str = "Learn JQuery";
sptr = "Learn C++";

printf("%s %s",str,sptr);
}

Options :

  1. Error : Lvalue Require
  2. Learn JQuery Learn C++
  3. Learn C Learn Java
  4. None Of these

Output:


Switch to String MCQ Home : Click Here


How and Why ?

  1. String Can be Initialized to Character Pointer
  2. String Cannot be Assigned to Array
  3. String Can be Copied into String Array Using Strcpy() Function