Point Out Correct Statements

Question 1 :

Which of the declaration is correct?


A). int length;
B). char int;
C). int long;
D). float double;
Answer : Option A

Explanation :

int length; denotes that variable length is int(integer) data type.
char int; here int is a keyword cannot be used a variable name.
int long; here long is a keyword cannot be used a variable name.
float double; here double is a keyword cannot be used a variable name.
So, the answer is int length;(Option A).


Question 2 :

Which of the following operations are INCORRECT?


A). int i = 35; i = i%5;
B). short int j = 255; j = j;
C). long int k = 365L; k = k;
D). float a = 3.14; a = a%3;
Answer : Option D

Explanation :

float a = 3.14; a = a%3; gives "Illegal use of floating point" error.
The modulus (%) operator can only be used on integer types. We have to use fmod() function in math.h for float values.


Question 3 :

Which of the following correctly represents a long double constant?


A). 6.68
B). 6.68L
C). 6.68f
D). 6.68LF
Answer : Option B

Explanation :

6.68 is double.
6.68L is long double constant.
6.68f is float constant.
6.68LF is not allowed in c.


Question 4 :

Which of the structure is incorrcet?

1 : 	
struct aa {
    int a;
    float b;
};

2 : 	
struct aa {
    int a;
    float b;
    struct aa var;
};

3 : 	
struct aa {
    int a;
    float b;
    struct aa *var;
};


A). 1
B). 2
C). 3
D). 1, 2, 3
Answer : Option B

Explanation :

Option B gives "Undefined structure in 'aa'" error.


Question 5 :

Which of the structure is correct?

1 : 	
struct book {
    char name[10];
    float price;
    int pages;
};

2 : 	
struct aa {
    char name[10];
    float price;
    int pages;
}

3 : 	
struct aa {
    char name[10];
    float price;
    int pages;
}


A). 1
B). 2
C). 3
D). All of above
Answer : Option A

Explanation :

In 2 and 3 semicolon are missing in structure element.


Question 6 :

1 :
typedef long a;
extern int a c;

2 :
typedef long a;
extern a int c;

3 :
typedef long a;
extern a c;


A). 1 correct
B). 2 correct
C). 3 correct
D). 1, 2, 3 are correct
Answer : Option C

Explanation :

typedef long a;
extern int a c; while compiling this statement becomes extern int long c;. This will result in to "Declaration syntax error".

typedef long a;
extern a int c; while compiling this statement becomes extern long int c;. This will result in to "Too many types in declaration error".

typedef long a;
extern a c; while compiling this statement becomes extern long c;. This is a valid c declaration statement. It says variable c is long data type and defined in some other file or module.

So, Option C is the correct answer.