Home » C Programming » Pointers » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    struct color
    {
    int color_code;
    char color_name[20];
    };
    void main()
    {
    color c;
    c.color_name = "Yellow";
    printf("Yellow");
    }
    1. Yellow
    2. Garbage value
    3. Compilation Error
    4. Nothing
    5. None of these
Correct Option: C

Compilation Error

main.c: In function ‘main’:
main.c:9:9: error: unknown type name ‘color’; use ‘struct’ keyword to refer to the type
color c;
^~~~~
struct
main.c:10:10: error: request for member ‘color_name’ in something not a structure or union
c.color_name = "Yellow";



Your comments will be displayed only after manual approval.