301 views
0 votes
0 votes

#include<stdio.h>
#include<string.h>
int main()
{
    
    char fullname[]="abcd";
    char firstname[]="xxxxx";
    //char lastName[]='Nagula';
    printf("enter number\n");
    printf("Press 1 for fullname\n"); 
    printf("Press 2 for firstname\n");
    printf("Press 3 for lastname\n");
    int a=0;
    scanf("%d",&a);
    
    //-----it is working------
                        char name[]= ( a==1 ? fullname : firstname); //error
    printf("name is %s",name);
    
    //----it is working-----
//    int n = (a==1 ? 10 :15);  //it is working 
//    printf("name is %d",n);
    
}

this code is not giving output it is giving

error :invalid initialiser in line char name[]= ( a==1 ? fullname : firstname);

how to correct it.

thank you..!

Please log in or register to answer this question.