Structures, Unions, Enums

Q1: Point out the error in the program?
#include<stdio.h>

int main()
{
    struct emp
    {
        char name[25];
        int age;
        float bs;
    };
    struct emp e;
    e.name = 'Suresh';
    e.age = 25;
    printf('%s %d\n', e.name, e.age);
    return 0;
}

A Error: Lvalue required/incompatible types in assignment

B Error: invalid constant expression

C Error: Rvalue required

D No error, Output: Suresh 25

ANS:A - Error: Lvalue required/incompatible types in assignment

We cannot assign a string to a struct variable like e.name = 'Suresh'; in C. We have to use strcpy(char *dest, const char *source) function to assign a string.

Ex: strcpy(e.name, 'Suresh');



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.