7. What will be the output of the program ?

#include<stdio.h>
 
int main()
{
    int x=30, *y, *z;
    y=&x; /* Assume address of x is 500 and integer is 4 byte size */
    z=y;
    *y++=*z++;
    x++;
    printf("x=%d, y=%d, z=%d\n", x, y, z);
    return 0;
}
  • x=31, y=502, z=502
  • x=31, y=500, z=500
  • x=31, y=498, z=498
  • x=31, y=504, z=504

8. Which of the statements is correct about the program?

#include<stdio.h>
 
int main()
{
    int arr[3][3] = {1, 2, 3, 4};
    printf("%d\n", *(*(*(arr))));
    return 0;
}
  • Output: Garbage value
  • Output: 1
  • Output: 3
  • Error: Invalid indirection

Explanation ***arr (Third dereference):

  • Here is the problem. You are now trying to apply the dereference operator (*) to the integer value 1.
  • In C, you can only dereference pointers (memory addresses). You cannot dereference a plain integer.
  • Because the operand is an int and not a pointer, the compiler throws an error: “Invalid indirection” (meaning you are trying to follow a pointer that isn’t there).

11. Point out the error in the program?

#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
    char name[20];
    int age;
};
int main()
{
    struct emp e = {"Sanjay", 35};
    modify(&e);
    printf("%s %d", e.name, e.age);
    return 0;
}
void modify(struct emp *p)
{
     p ->age=p->age+2;
}
  • Error: in structure
  • Error: in prototype declaration unknown struct emp
  • No error
  • None of above

Explanation The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.


12. Point out the error in the program?

#include<stdio.h>
 
int main()
{
    struct a
    {
        float category:5;
        char scheme:4;
    };
    printf("size=%d", sizeof(struct a));
    return 0;
}
  • Error: invalid structure member in printf
  • Error in this float category:5; statement
  • No error
  • None of above

Explanation Bit field type must be signed int or unsigned int. The char type: char scheme:4; is also a valid statement.