Tuesday, 31 October 2017

C MCQ - Variable and Datatypes

1. Which of the following is not valid variable name declaration?
a) int __v1;
b) int __1v;
c) int __V1;
d) None

2. Which of the following is not a valid variable name declaration?
a) int _v1;
b) int v_1;
c) int 1_v;
d) int _1v

Explanation:Variable name can't start with a digit.

3. Variable names beginning with underscore is not encouraged. Why?
a) It is not standard form
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system


4. Which is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;


5.Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names can't start with a digit
d) Variable can be of any length


6.  What will be the output?

    #include <stdio.h>
    int main()
        int main = 5;
        printf("%d", main);
        return 0;
a) compile-time error
b) run-time error
c) run without any error and prints 5
d) experience infinite looping

Explanation:A C program can have same function name and same variable name.

7.  Which of the following cannot be a variable name in C?
a) friend
b) true
c) volatile
d) export

Ans: c
Explanation:volatile is C keyword

8. The format identifier ‘%i’ is also used for _____ data type?
a) char
b) double
c) float
d) int

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

9. Which of the following is a User-defined data type?
a) struct {char name[10], int age};
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) typedef int Boolean;
d) all of the mentioned


10. What is short int in C programming?
a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic datatype
d) All of the mentioned


11. What is the output of this C code?

    #include  <stdio.h>
    int main()
       signed char chr;
       chr = 128;
       printf("%d\n", chr);
       return 0;
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned

Explanation:signed char will be a negative number.

12. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined


13. Which of the datatypes have size that is variable?
a) int
b) struct
c) float
d) double

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

14. What is the output of this C code?

    #include <stdio.h>
    int main()
        float x = 'a';
        printf("%f", x);
        return 0;
a) 97.000000
b) run time error
c) a.0000000
d) a

Explanation:Since the ASCII value of a is 97, the same is assigned to the float variable and printed.

15. Which is correct with respect to size of the datatypes?
a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > int


No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...