Friday, 24 July 2015

TYPEDEF OBJECTIVE PROBLEMS

Q1-In the following code, the P2 is Integer Pointer or Integer?
typedef int *ptr;
ptr p1, p2;
A.IntegerB.Integer pointer
C.Error in declarationD.None of above

ANS - B;
EXPLANATION

 typedef int* ptr is same as typedef int *ptr in case of typedef declaration .


2. 
In the following code what is 'P'?
typedef char *charp;
const charp P;
A.P is a constantB.P is a character constant
C.P is character typeD.None of above

ANS - non
 now p is a contant pointer .
note --typedef const char *charp;  this is not a valid declaration since typedef doesn't declare an instance of a variable, it declares a type (type alias actually),
const is a qualifier you apply to an instance, not a type, so you can use static when you use the type.

3. 
What is x in the following program?
#include<stdio.h>

int main()
{
    typedef char (*(*arrfptr[3])())[10];
    arrfptr x;
    return 0;
}
A.x is a pointer
B.x is an array of three pointer
C.x is an array of three function pointers
D.Error in x declaration
ans- c

explanation
The return value of the function whose function pointer can be any of arrfptr[n]will be a pointer to an array of 10 characters. 

The declaration can interpreted as "type of the array to be returned by function(char) (Returning char pointer(*)(function pointer name(*arrfptr)[size of the array of function pointers](3)(parameters)(void))[size of the array which will be returned from the function].
#include<stdio.h>

int main()
{
    enum color{red, green, blue};
    typedef enum color mycolor;
    mycolor m = red;
    printf("%d", m);
    return 0;
}

No comments:

Post a Comment