C Datatypes Q & A

C Datatypes Q & A


Ques 1. What is the output of following program. Assume that the numbers are stored in 2's complement form.

#include<stdio.h> 
int main()
{
   int m = -2;
   int n = ~1;

   printf("0x%x 0x%x ", m, n);

   return 0;
}

options:
A. 0xfffffffe 0xfffffffe
B. compiler error
C. -2 -2
D. -2 -1


Ques 2. which is invalid in the following code declaration in C?

1. short int q;
2. signed long a
3. long e;
4. unsigned short r;

options:
A. 1 & 2 valid 
B. 3 valid
C. 4 valid
D. all valid



Ques 3. what is the output for the below code?

#include<stdio.h>
int main()
{
   float x = 15.0,z;
   z = 9/5 * x+32;
   printf("z=%0.2f",z);
   return 0;
}


options:
A. 47.00
B. 59.00
C. 32.00
D. 45.00



Ques 4. what is the output for the below code?

#include<stdio.h>
int main()
{
   char d = '\022';
   char e = 022;
    printf("%d %d", d,e);
    return 0;
}

options:
A. 50 18
B. 22 22
C. Compile time error
D. run time error



Ques 5. In C, sizes of an integer and a pointer always same.

options:
A. True
B. False


Ques 6. what is the output for the below code?
int main()
{
    void *gptr, g;
    g = 0;
    gptr = &g;
    printf("%v", *gptr);
    getchar();
    return 0;
}

options:
A. 0
B. runtime error
C. 48
D. Compile time error



Ques 7. what is the output for the below code?

#include<stdio.h>
int main()
{
    char m=0;
    char ch = 125;
    ch = ch+10;
    printf("%d\n ", ch);
    return 0;
}

options:
A. -121
B. 121 
C. 135 
D. compile time error



Ques 8. what is the output ?

#include<stdio.h>
int main()
{
    int x = -1;
    printf(" %x %x\n", x, sizeof(long));
    return 0;
}

options:
A. ffffffff 4
B. -1 4
C. compiler error
D. None of the above


Ques 9. what is the output for the below code?

#include<stdio.h>
int main()
{
    float x = 0.1;

    if ( x == 0.1 )
        printf("IF");
    else if (x == 0.1f)
        printf("ELSE IF");
    else
        printf("ELSE");
}


options:
A. ELSE IF
B. ELSE
C. IF
D. error


Ques 10. what is the output for the below code?

#include<stdio.h>
int main()
{
    char t = 125;
    int i;

    for(i=0; i<5; i++)
      printf("%d ", t++);

    return 0;
}

options:
A. 125 126 127 128 129
B. 125 126 127 -128 -127
C. infinete loop
D. none of the above 



Ques 11. what is the output for the below code?

#include<stdio.h>
int main()
{
    char t = 0;
    for(t=0; t<135; t++)
      printf("\n%d", t);
    return 0;
}

options:
A. prints 0 to 135
B. infinite loop
C. error
D. runtime error


Ques 12.  Which data type is most suitable for storing a number 65000 in a 32-bit system?

options:
A. signed short
B. unsigned short
C. long
D. int



Ques 13: Which of the following is a User-defined data type?

options:
A. typedef int signedint32;
B. typedef enum {Jan, Feb, Mar, Apr, MAy} Months;
C. struct {char str[10], int age};
D. all of the mentioned


Ques 14: What is the size of an int data type?

Options:
A. 4 bytes
B. 8 bytes
C. Depends on the system /compiler
D. 2 bytes

Ques 15:  What is the output for the below program?
#include<stdio.h>
    int main()
    {
        char ch;
        int j = 0;
        FILE *file;
        file = fopen("test.txt", "w+");
        fprintf(file, "%c", 'd');
        fprintf(file, "%c", -1);
        fprintf(file, "%c", 'g');
        fclose(file);
        file = fopen("test.txt", "r");
        while ((ch = fgetc(file)) !=  -1)
            printf("%c", ch);
        return 0;
    }

options:

A. d
B. depends on what fgets returns
C. depends on compiler 
D. infinite loop


Ques 16: What is the output for the below program?
#include<stdio.h>
int main()
{
    void *gptr;
    int *g;
    gptr=(int *)malloc(4);
    g=(int* ) gptr;
    *g=43;
    *(int *)gptr=34;
    printf("%d %d", *g, *(int*)gptr);

    getchar();
    return 0;
}

options:
A. 34 34
B. 35 35
C. compiler error
D. run time error


Ques 17: What is the output for the below program?
#include<stdio.h>
int main()
{
     int x,y;
    double d;

    x=44, y=5;
    d=x/y;
    printf("%lf", d);

    return 0;
}

options:
A. 8.80000
B. 8.0000
C. compiler error
D. run time error


Ques 18: What is the output for the below program?
#include<stdio.h>

int main()
{
    float x,y;
    double d;

    x=4.0, y=5.0;
    d=x/y/x;
    printf("%lf", d);

    return 0;
}

options:
A. 0.8000
B. 3.2000
C. 0.2000
D. run time error


Ques 19: What is the output for the below program?
#include<stdio.h>

int main()
{
    unsigned int m=121;
    signed int i=225;
    char c=34;

    c=i+m;    
    printf("%d",c);
    return 0;
}
options:
A. runtime error
B. compiler error
C. 346
D. 90

Ques 20: What is the output for the below program?
#include<stdio.h>
int main()
{
    unsigned int m = 65632;
    signed short i=225;
    i = m;
    printf("%i",i);
    return 0;
}

options:
A. 65632
B. 65631 
C. 96
D. 97

Answers

1. A 2. D 3. A 4. A 5. B 6. D 7. A 8. A 9. A 10. B 11. B 12. B 13. D 14. C 15. A 16. A 17. B 18. C 19. D 20. C