Exercise: Declarations And Initializations

Questions for: Declarations And Initializations

Which of the following correctly represents a long double constant?
A:
6.68
B:
6.68L
C:
6.68f
D:
6.68LF
Answer: B

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

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: D

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.

Which of the declaration is correct?
A:
int length;
B:
char int;
C:
int long;
D:
float double;
Answer: A

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).

Point out the error in the following program.
#include<stdio.h>
int main()
{
    int (*p)() = fun;
    (*p)();
    return 0;
}
int fun()
{
    printf("ExamAdept.com\n");
    return 0;
}
A:
Error: in int(*p)() = fun;
B:
Error: fun() prototype not defined
C:
No error
D:
None of these
Answer: B

The compiler will not know that the function int fun() exists. So we have to define the function prototype of int fun();
To overcome this error, see the below program


#include<stdio.h>
int fun(); /* function prototype */

int main()
{
    int (*p)() = fun;
    (*p)();
    return 0;
}
int fun()
{
    printf("ExamAdept.com\n");
    return 0;
}
Which of the following is correct about err used in the declaration given below?
 typedef enum error { warning, test, exception } err;
A:
It is a typedef for enum error.
B:
It is a variable of type enum error.
C:
The statement is erroneous.
D:
It is a structure.
Answer: A

A typedef gives a new name to an existing data type.
So err is a new name for enum error.

Ad Slot (Above Pagination)
Quiz