Compilation
Question 1 |
What error would the following function given on compilation?
f(int a, int b)
{
int a;
a=20;
return a;
}
f(int a, int b)
{
int a;
a=20;
return a;
}
Missing parenthesis is return statement | |
Function should be defined as int f(int a, int b) | |
Redeclaration of a | |
None of these |
Question 1 Explanation:
We are already declared variable name ‘a’ in function. Again we are declared inside the function. So, the compiler will raise a error “Redeclaration of a”
Question 2 |
What will be output if you will compile and execute the following C code?
void main()
{
char c=125;
c=c+10;
printf("%d",c);
}
135 | |
115 | |
-121 | |
-8 |
Question 2 Explanation:
As we know any data type shows cyclic properties
In our example the data type is char data type , so if you will increase or decrease the char
variables beyond its maximum or minimum value respectively it will repeat same value
according to following cyclic order
So,
125+1= 126
125+2= 127
125+3=-128
125+4=-127
125+5=-126
125+6=-125
125+7=-124
125+8=-123
125+9=-122
125+10=-121
In our example the data type is char data type , so if you will increase or decrease the char
variables beyond its maximum or minimum value respectively it will repeat same value
according to following cyclic order
So,
125+1= 126
125+2= 127
125+3=-128
125+4=-127
125+5=-126
125+6=-125
125+7=-124
125+8=-123
125+9=-122
125+10=-121
Question 3 |
What will be output if you will compile and execute the following C code?
void main()
{
printf("%d",sizeof(5.2)); }
4 | |
8 | |
2 | |
16 |
Question 3 Explanation:
Size of is a special operator will return number of bytes of data types. By default system will take integer data type,if we are not specifying any data type. Total size is 4 bytes.
Question 4 |
Which of the following has the compilation error in C?
int n=17; | |
char c=99; | |
float f=(float)99.32; | |
#include |
Question 4 Explanation:
Option A: General declaration of integer variable.
Option B: General declaration of character variable.
Option C: It is type casting. But given cast also same type.
Option D: We have to include a file otherwise it treated as compiler error.
Option B: General declaration of character variable.
Option C: It is type casting. But given cast also same type.
Option D: We have to include a file otherwise it treated as compiler error.
Question 5 |
A condition that is caused by run time error in a computer program is known as
Exception | |
Syntax error | |
Semantic error | |
Fault |
Question 5 Explanation:
● An exception is an abnormal or unprecedented event that occurs after the execution of a software program or application. It is a runtime error of an undesired result or event affecting normal program flow.
● An exception is also known as a fault.
● An exception is also known as a fault.
Question 6 |
Which of the following has compilation error in C ?
int n=32 ; | |
char ch=65 ; | |
float f=(float)3.2 ; | |
none of the above |
Question 6 Explanation:
Option-A: ‘n’ is a integer value and and value of ‘n’ is 32.
Option-B: ‘ch’ is a character variable and value of ‘ch’ is 65.
Option-C: ‘f’ is a floating point variable and it uses type casting.
Option-D is correct answer.
Option-B: ‘ch’ is a character variable and value of ‘ch’ is 65.
Option-C: ‘f’ is a floating point variable and it uses type casting.
Option-D is correct answer.
There are 6 questions to complete.