Units

### Unit: Data Types And Sizes - Questions and Answers

Practice these Data Types And Sizes under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Data Types And Sizes for following purpose.

– Anyone who is wishing to increase their perfect knowledge of Data Types And Sizes of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Data Types And Sizes.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Data Types And Sizes under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Data Types And Sizes topic of C Programming:

1.

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

Explanation:

typedef and struct are used to define user-defined data types.

2.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        float x = 'a';`
5. `        printf("%f", x);`
6. `        return 0;`
7. `    }`

Explanation:

Since the ASCII value of a is 97, the same is assigned to the float variable and printed.
Output:
\$ cc pgm8.c
\$ a.out
97.000000

3.

Which of the datatypes have size that is variable?

Explanation:

Since the size of the structure depends on its fields, it has a variable size.

4.

Comment on the output of this C code?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        int a[5] = {1, 2, 3, 4, 5};`
5. `        int i;`
6. `        for (i = 0; i < 5; i++)`
7. `            if ((char)a[i] == '5')`
8. `                printf("%d\n", a[i]);`
9. `            else`
10. `                printf("FAIL\n");`
11. `    }`

Explanation:

The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
\$ cc pgm1.c
\$ a.out
FAILED
FAILED
FAILED
FAILED
FAILED

5.

What is the size of an int data type?

Explanation:

The size of the data types depend on the system.

6.

Comment on the output of this C code?

1. `    #include  <stdio.h>`
2. `    int main()`
3. `    {`
4. `        char c;`
5. `        int i = 0;`
6. `        FILE *file;`
7. `        file = fopen("test.txt", "w+");`
8. `        fprintf(file, "%c", 'a');`
9. `        fprintf(file, "%c", -1);`
10. `        fprintf(file, "%c", 'b');`
11. `        fclose(file);`
12. `        file = fopen("test.txt", "r");`
13. `        while ((c = fgetc(file)) !=  -1)`
14. `            printf("%c", c);`
15. `        return 0;`
16. `    }`

Explanation:

Output:
\$ cc pgm3.c
\$ a.out
a

7.

Comment on the output of this C code?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        float f1 = 0.1;`
5. `        if (f1 == 0.1)`
6. `            printf("equal\n");`
7. `        else`
8. `            printf("not equal\n");`
9. `    }`

Explanation:

0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.
Output:
\$ cc pgm4.c
\$ a.out
not equal

8.

What is short int in C programming?

Explanation:

9.

What is the output of the following C code(on a 64 bit machine)?

1. `    #include <stdio.h>`
2. `    union Sti`
3. `    {`
4. `        int nu;`
5. `        char m;`
6. `    };`
7. `    int main()`
8. `    {`
9. `        union Sti s;`
10. `        printf("%d", sizeof(s));`
11. `        return 0;`
12. `    }`

Explanation:

Since the size of a union is the size of its maximum datatype, here int is the largest hence 4.
Output:
\$ cc pgm7.c
\$ a.out
4

10.

What is the output of this C code (on a 32-bit machine)?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        int x = 10000;`
5. `        double y = 56;`
6. `        int *p = &x;`
7. `        double *q = &y;`
8. `        printf("p and q are %d and %d", sizeof(p), sizeof(q));`
9. `        return 0;`
10. `    }`

Explanation:

Size of any type of pointer is 4 on a 32-bit machine.
Output:
\$ cc pgm6.c
\$ a.out
p and q are 4 and 4

11.

What is the output of this C code?

1. `    #include  <stdio.h>`
2. `    int main()`
3. `    {`
4. `       signed char chr;`
5. `       chr = 128;`
6. `       printf("%d\n", chr);`
7. `       return 0;`
8. `    }`

Explanation:

signed char will be a negative number.
Output:
\$ cc pgm2.c
\$ a.out
-128

12.

The format identifier ‘%i’ is also used for _____ data type?

Explanation:

Both %d and %i can be used as a format identifier for int data type.

13.

Comment on the output of this C code?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        float f1 = 0.1;`
5. `        if (f1 == 0.1f)`
6. `            printf("equal\n");`
7. `        else`
8. `            printf("not equal\n");`
9. `    }`

Explanation:

0.1f results in 0.1 to be stored in floating point representations.
Output:
\$ cc pgm5.c
\$ a.out
equal

14.

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