AmbitionBox

Discover Best Places to work in India

C Programming

C Programming Questions and Answers

Showing 11 - 13 of 13 questions

11

Point out the error in the program?

#include < stdio.h >int main()
{
    struct bits
    {
        float f:2;
    }bit;

    printf("%d\n", sizeof(bit));
    return0;
}
a

4

b

2

c

Error: cannot set bit field for float

d

Error: Invalid member access in structure

correct answer
Answer :

Option C

12

Point out the error in the program?

#include < stdio.h >int main()
{
    struct bits
    {
        float f:2;
    }bit;

    printf("%d\n", sizeof(bit));
    return0;
}
a

4

b

2

c

Error: cannot set bit field for float

d

Error: Invalid member access in structure

correct answer c
Answer :

Option C

13

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);
    return0;
}
a

Error: Lvalue required/incompatible types in assignment

b

Error: invalid constant expression

c

Error: Rvalue required

d

No error, Output: Suresh 25

correct answer a
Answer :

Option A

Explanation :

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");

Select a company to compare with

vs

Similar Companies