C Programming

C Programming

Complicated Declarations has 37 Questions
Declare the following statement?
"An array of three pointers to chars".

char *ptr[3]();
char *ptr[3];
char (*ptr[3])();
char **ptr[3];
What will be the output of the program?
#include<stdio.h>

int main()
{
    char far *near *ptr1;
    char far *far *ptr2;
    char far *huge *ptr3;
    printf("%d, %d, %d", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
}

4, 4, 8
4, 4, 4
2, 4, 4
2, 4, 8
Point out the error in the following program (in Turbo C under DOS).
#include<stdio.h>

union emp
{
    int empno;
    int age;
};

int main()
{
    union emp e = {10, 25};
    printf("%d %d", e.empno, e.age);
    return 0;
}

Error: Lvalue required
Error: Rvalue required
Error: cannot initialize more than one union member.
No error
Does the data type of all elements in the union will be same.

True
False
Is following declaration is correct?
typedef *void (*pfun)(**int, *float);

Yes
No
What do the following declaration signify?
int *ptr[30];

ptr is a pointer to an array of 30 integer pointers.
ptr is a array of 30 pointers to integers.
ptr is a array of 30 integer pointers.
ptr is a array 30 pointers.
What will be the output of the program in DOS (Compiler - Turbo C)?
#include<stdio.h>
double i;

int main()
{
    (int)(float)(char) i;
    printf("%d", sizeof((int)(float)(char)i));
    return 0;
}

1
2
4
8
Point out the error in the following program.
#include<stdio.h>
#include<stdlib.h>

int main()
{
    static char *p = (char *)malloc(10);
    return 0;
}

Error: Lvalue required
Error: Rvalue required
Error: invalid *p declaration
No error
It is not necessary to typecast the address returned by malloc().

True
False
Is following declaration is correct?
char (* ( *f())[])();

Yes
No
Declare the following statement?
"A pointer to an array of three chars".

char *ptr[3]();
char (*ptr)*[3];
char (*ptr[3])();
char (*ptr)[3];
What will be the output of the program?
#include<stdio.h>

int main()
{
    char huge *near *far *ptr1;
    char near *far *huge *ptr2;
    char far *huge *near *ptr3;
    printf("%d, %d, %d", sizeof(**ptr1), sizeof(ptr2), sizeof(*ptr3));
    return 0;
}

4, 4, 4
2, 2, 2
2, 8, 4
2, 4, 8
Point out the error in the following program.
#include<stdio.h>
void display(int (*ff)());

int main()
{
    int show();
    int (*f)();
    f = show;
    display(f);
    return 0;
}
void display(int (*ff)())
{
    (*ff)();
}
int show()
{
    printf("ASTIWZ");
}

Error: invalid parameter in function display()
Error: invalid function call f=show;
No error and prints "ASTIWZ"
No error and prints nothing.
We can modify the pointers "source" as well as "target".

True
False
Is following declaration is correct?
char far *far *ptr;

Yes
No
What do the following declaration signify?
char *arr[10];

arr is a array of 10 character pointers.
arr is a array of function pointer.
arr is a array of characters.
arr is a pointer to array of characters.
What will be the output of the program (in Turbo C under DOS)?
#include<stdio.h>

int main()
{
    char huge *near *far *ptr1;
    char near *far *huge *ptr2;
    char far *huge *near *ptr3;
    printf("%d, %d, %d", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
}

4, 4, 8
2, 4, 4
4, 4, 2
2, 4, 8
Function can return a floating point number.

True
False
Is following declaration is correct?
void(*f)(int, void(*)());

Yes
No
What do the following declaration signify?
int (*pf)();

pf is a pointer to function.
pf is a function pointer.
pf is a pointer to a function which return int
pf is a function of pointer variable.
What will be the output of the program?
#include<stdio.h>
typedef void v;
typedef int i;

int main()
{
    v fun(i, i);
    fun(2, 3);
    return 0;
}
v fun(i a, i b)
{
    i s=2;
    float i;
    printf("%d,", sizeof(i));
    printf(" %d", a*b*s);
}

2, 8
4, 8
2, 4
4, 12
We can allocate a 2-Dimensional array dynamically.

True
False
Are the following declarations same?
char far *far *scr;
char far far** scr;

Yes
No
Declare the following statement?
"A pointer to a function which receives an int pointer and returns float pointer".

float *(ptr)*int;
float *(*ptr)(int)
float *(*ptr)(int*)
float (*ptr)(int)
What will be the output of the program?
#include<stdio.h>

int main()
{
    char huge *near *far *ptr1;
    char near *far *huge *ptr2;
    char far *huge *near *ptr3;
    printf("%d, %d, %d", sizeof(ptr1), sizeof(*ptr2), sizeof(**ptr3));
    return 0;
}

4, 4, 4
2, 4, 4
4, 4, 2
2, 4, 8
What do the following declaration signify?
void *cmp();

cmp is a pointer to an void type.
cmp is a void type pointer variable.
cmp is a function that return a void pointer.
cmp function returns nothing.
What will be the output of the program?
#include<stdio.h>
typedef unsigned long int uli;
typedef uli u;

int main()
{
    uli a;
    u b = -1;
    a = -1;
    printf("%lu, %lu", a, b);
    return 0;
}

4343445454, 4343445454
4545455434, 4545455434
4294967295, 4294967295
Garbage values
Declare the following statement?
"A pointer to a function which receives nothing and returns nothing".

void *(ptr)*int;
void *(*ptr)()
void *(*ptr)(*)
void (*ptr)()
What will be the output of the program in DOS (Compiler - Turbo C)?
#include<stdio.h>
double i;

int main()
{
    (int)(float)(char) i;
    printf("%d",sizeof(i));
    return 0;
}

4
8
16
22
What do the following declaration signify?
int *f();

f is a pointer variable of function type.
f is a function returning pointer to an int.
f is a function pointer.
f is a simple declaration of pointer variable.
What will be the output of the program?
#include<stdio.h>

int main()
{
    char huge *near *far *ptr1;
    char near *far *huge *ptr2;
    char far *huge *near *ptr3;
    printf("%d, %d, %d", sizeof(ptr1), sizeof(**ptr2), sizeof(ptr3));
    return 0;
}

4, 4, 4
4, 2, 2
2, 8, 4
2, 4, 8
What do the following declaration signify?
void (*cmp)();

cmp is a pointer to an void function type.
cmp is a void type pointer function.
cmp is a function that return a void pointer.
cmp is a pointer to a function which returns void .
What will be the output of the program?
#include<stdio.h>

int main()
{
    struct s1
    {
        char *z;
    int i;
    struct s1 *p;
    };
    static struct s1 a[] = {{"Nagpur", 1, a+1} , {"Chennai", 2, a+2} , 
                            {"Bangalore", 3, a} };

    struct s1 *ptr = a;
    printf("%s,", ++(ptr->z));
    printf(" %s,", a[(++ptr)->i].z);
    printf(" %s", a[--(ptr->p->i)].z);
    return 0;
}

Nagpur, Chennai, Bangalore
agpur, hennai, angalore
agpur, Chennai, angalore
agpur, Bangalore, Bangalore
What do the following declaration signify?
char **argv;

argv is a pointer to pointer.
argv is a pointer to a char pointer.
argv is a function pointer.
argv is a member of function pointer.
What will be the output of the program?
#include<stdio.h>

int main()
{
    char huge *near *ptr1;
    char huge *far *ptr2;
    char huge *huge *ptr3;
    printf("%d, %d, %d", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
}

4, 4, 8
2, 4, 4
4, 4, 2
2, 4, 8
What do the following declaration signify?
char *scr;

scr is a pointer to pointer variable.
scr is a function pointer.
scr is a pointer to char.
scr is a member of function pointer.
What will be the output of the program in Turbo C?
#include<stdio.h>

int main()
{
    char near *near *ptr1;
    char near *far *ptr2;
    char near *huge *ptr3;
    printf("%d, %d, %d", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
    return 0;
}

4, 4, 8
4, 4, 4
2, 4, 8
2, 4, 4