3. What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

#include<stdio.h>
 
int main()
{
    int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
    return 0;
}
  • 448, 4, 4
  • 520, 2, 2
  • 1006, 2, 2
  • Error

Explains: Part A: a[0] + 1

  • What is a[0]? a is a 2D array. a[0] represents the first row (an array of 4 integers).
  • Decay: When used in an expression, an array name decays into a pointer to its first element. So, a[0] becomes a pointer to a[0][0].
    • Type: int *
    • Current Address: 1002
  • The Arithmetic: In C, adding 1 to a pointer increases the address by the size of the type it points to (sizeof(int) = 4 bytes).
    • Calculation: .
  • Result: 1006

Part B: *(a[0] + 1)

  • This uses the exact same logic as Part A, but with the dereference operator (*) at the front.
  • We calculated that (a[0] + 1) points to the address 1006.
  • The * tells the program: “Go to address 1006 and get the value stored there.”
  • Looking at our memory map, the value at 1006 is 2.
  • Result: 2

Part C: *(*(a + 0) + 1)

  • This looks complex, but it is just a different way of writing Part B.
  • *(a + 0): a points to the rows. a + 0 is the first row. Dereferencing a row pointer *(a+0) gives you the row array itself, which is equivalent to a[0].
  • So, the expression simplifies: ((a + 0) + 1) *(a[0] + 1)
  • This is identical to Part B.
  • Result: 2

5. What does the following declaration mean?

int (*ptr)[10];
  • ptr is array of pointers to 10 integers
  • ptr is a pointer to an array of 10 integers
  • ptr is an array of 10 integers
  • ptr is an pointer to array

6. What will be the output of the program in Turbo-C?

#include<stdio.h>
 
int main()
{
    int arr[5], i=-1, z;
    while(i<5)
        arr[i]=++i;
 
    for(i=0; i<5; i++)
        printf("%d, ", arr[i]);
 
    return 0;
}
  • 1, 2, 3, 4, 5,
  • -1, 0, 1, 2, 3, 4
  • 0, 1, 2, 3, 4,
  • 0, -1, -2, -3, -4,

Explains: Turbo-C typically evaluates the right-hand side (the increment) before it determines the index on the left-hand side.

8. Point out the error in the program?

#include<stdio.h>
 
int main()
{
    struct emp
    {
        char name[20];
        float sal;
    };
    struct emp e[10];
    int i;
    for(i=0; i<=9; i++)
        scanf("%s %f", e[i].name, &e[i].sal);
    return 0;
}
  • Error: invalid structure member
  • Error: Floating point formats not linked (For Turbo C)
  • No error (For Modern C)
  • None of above

16. If the different command line arguments are supplied at different times would the output of the following program change?

#include<stdio.h>
 
int main(int argc, char **argv)
{
    printf("%d\n", argv[argc]);
    return 0;
}
  • Yes
  • No

17. What will be the output of the program?

#include<stdio.h>
 
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
    ERROR e;
    e.err=1;
    printf("%d\n", e.err);
    return 0;
}
  • 0
  • 1
  • 2
  • Error

20. Data written into a file using fwrite() can be read back using fscanf()

  • True
  • False

Explanation fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.