Basics, Operators, I/O Functions,: Conditional and Looping Statement Basics 1
Basics, Operators, I/O Functions,: Conditional and Looping Statement Basics 1
Basics
1.
Which of the following special symbol allowed in a variable name?
A.* (asterisk) B.| (pipeline)
C.- (hyphen) D._ (underscore)
Answer: Option D
2.
Answer: Option D
Explanation:
Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535.
Step 1:unsigned int i = 65536; here variable i becomes '0'(zero). because unsigned int varies
from 0 to 65535.
Step 2: while(i != 0) this statement becomes while(0 != 0). Hence the while(FALSE)
condition is not satisfied. So, the inside the statements of while loop will not get executed.
Note: Don't forget that the size of int should be 2 bytes. If you run the above program in GCC
it may run infinite loop, because in Linux platform the size of the integer is 4 bytes.
3.
Answer: Option A
Explanation:
#include<stdio.h>
#include<math.h>
int main()
{
printf("\n Result : %f" , ceil(1.44) );
printf("\n Result : %f" , ceil(1.66) );
return 0;
}
// Output:
// Result : 2.000000
// Result : 2.000000
// Result : 1.000000
// Result : 1.000000
4.
Answer: Option A
Explanation:
if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is
greater than the float variable a. Hence the if condition is satisfied and it prints 'Hi'
Example:
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Output:
0.7000000000 0.6999999881
2)
What will be output of the following program?
#include<stdio.h>
int main(){
int i=5,j;
j=++i+++i+++i;
printf("%d %d",i,j);
return 0;
}
Explanation
j=8+8+8
j=24 and
i=8
What will be output of the following program?
#include<stdio.h>
int main(){
int i=1;
i=2+2*i++;
printf("%d",i);
return 0;
i = 2 + 2 * 1
i = 4
Now i will be incremented by one so i = 4 + 1 = 5
(5)
What will be output of the following program?
#include<stdio.h>
void main(){
int x;
x=10,20,30;
printf("%d",x);
return 0;
}
Explanation
Output: 10
Explanation :
Precedence table:
#include<stdio.h>
int main(){
int a=0,b=10;
if(a=0){
printf("true");
}
else{
printf("false");
}
return 0;
}
Explanation
Output: false
(7)
What will be output of the following program?
#include<stdio.h>
int main(){
int a;
a=015 + 0x71 +5;
printf("%d",a);
return 0;
}
Explanation
Output: 131
#include<stdio.h>
int main(){
printf("%d %d %d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L));
return 0;
}
Explanation
Output:
#include<stdio.h>
int main(){
int x=100,y=20,z=5;
printf("%d %d %d");
return 0;
}
Explanation
Output:
#include<stdio.h>
int main(){
int a;
a=sizeof(!5.6);
printf("%d",a);
return 0;
}
Explanation
Output:: 2
Explanation:
! is negation operator it return either integer 0 or 1.
! Any operand = 0 if operand is non zero.
! Any operand = 1 if operand is zero.
So, !5.6 = 0
Since 0 is integer number and size of integer data type is two byte.
#include<stdio.h>
int main(){
float a;
(int)a= 45;
printf("%d,a);
return 0;
}
Explanation
Output:
Turbo C++ 3.0: Compilation error
Explanation:
After performing any operation on operand it always return some constant value.
(int) i.e. type casting operator is not exception for this. (int) a will return one constant value
and we cannot assign any constant value to another constant value in c.