C Programming

C Programming

Typedef has 15 Questions

In the following code, the P2 is Integer Pointer or Integer?
typedef int *ptr;
ptr p1, p2;

Integer
Integer pointer
Error in declaration
None of above
What will be the output of the program?
#include<stdio.h>

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

1
0
2
red
In the following code snippet can we declare a new typedef named ptr even though struct employee has not been completely declared while using typedef?
typedef struct employee *ptr;
struct employee
{
    char name[20];
    int age;
    ptr next;
}

Yes
No
Is the following declaration acceptable?
typedef long no, *ptrtono;
no n;
ptrtono p;

Yes
NO
In the following code what is 'P'?
typedef char *charp;
const charp P;

P is a constant
P is a character constant
P is character type
None of above
What is the output of the program?
typedef struct data;
{
    int x;
    sdata *b;
}sdata;

Error: Declaration missing ';'
Error: in typedef
No error
None of above
Point out the error in the following code?
typedef struct
{
    int data;
    NODEPTR link;
}*NODEPTR;

Error: in *NODEPTR
Error: typedef cannot be used until it is defined
No error
None of above
Is there any difference in the #define and typedef in the following code?
typedef char * string_t;
#define string_d char *;
string_t s1, s2;
string_d s3, s4;

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

int main()
{
    typedef char (*(*arrfptr[3])())[10];
    arrfptr x;
    return 0;
}

x is a pointer
x is an array of three pointer
x is an array of three function pointers
Error in x declaration
What will be the output of the program?
#include<stdio.h>

int main()
{
    typedef int arr[5];
    arr iarr = {1, 2, 3, 4, 5};
    int i;
    for(i=0; i<4; i++)
        printf("%d,", iarr[i]);
    return 0;
}

1, 2, 3, 4
1, 2, 3, 4, 5
No output
Error: Cannot use typedef with an array
Are the properties of i, j and x, y in the following program same?
typedef unsigned long int uli;
uli i, j;
unsigned long int x, y;

Yes
No
What will be the output of the program?
#include<stdio.h>

int main()
{
    typedef int LONG;
    LONG a=4;
    LONG b=68;
    float c=0;
    c=b;
    b+=a;
    printf("%d,", b);
    printf("%f", c);
    return 0;
}

72, 68.000000
72.000000, 68
68.000000, 72.000000
68, 72.000000
typedef's have the advantage that they obey scope rules, that is they can be declared local to a function or a block whereas #define's always have a global effect.

Yes
No
What will be the output of the program?
#include<stdio.h>

int main()
{
    typedef float f;
    static f *fptr;
    float fval = 90;
    fptr = &fval;
    printf("%f", *fptr);
    return 0;
}

9
0
90.000000
90
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", e.err);
    return 0;
}

0
1
2
Error