1. How would you round off a value 1.66 to 2.00 and truncate1.75 to 1.00 using C program?
#include<stdio.h>
#include<math.h>
void main()
{
float x=1.66;
float y=1.75;
printf(" %f %f",ceil(x),floor(y));
}
2. What is the storage class of i in the following statement?
int i;
ans: The storage class of i is auto if it is declared within the main() and extern if it is declared outside main().
3. Which of the following is not a logical operator?
a) & , b) &&, c) ||, d) !
ans: option a
4. What will be output of the following program?
#include<stdio.h>
void main()
{
int i=3;
i=i++;
printf("%d",i);
}
ans: 4
5. What will be output of the following program?
#include<stdio.h>
void main()
{
int x=4,y,z;
y=--x;
z=x--;
printf("%d %d %d",x,y,z);
}
ans: 2 3 3
6. We want to round off x, a float, to an int value. The correct way to do so will be?
a) y=(int)(x+0.5);
b) y=int(x+0.5);
c) y=(int)x+0.5;
d) y=(int)((int)x+0.5);
ans: option (a)
7. Is it true that too many recursive calls may result into stack overflow?
ans: yes
8. If the size of int is 4 byte , then what will be the output of the program?
#include<stdio.h>
void main()
{
int arr[]={12,13,14,15,16};
printf("%d %d %d",sizeof(arr), sizeof(*arr),sizeof(arr[0]));
}
ans: 20 4 4
9. What will be output of the following program?
#include<stdio.h>
void main()
{
char *str;
str="%d \n";
str++;
str++;
printf(str -2,300);
}
ans: 300
10. What will be output of the following program?
#include<stdio.h>
void main()
{
int i,*j,k;
i=3;
j=&i;
printf("%d",i**j*i+*j);
}
ans:30
#include<stdio.h>
#include<math.h>
void main()
{
float x=1.66;
float y=1.75;
printf(" %f %f",ceil(x),floor(y));
}
2. What is the storage class of i in the following statement?
int i;
ans: The storage class of i is auto if it is declared within the main() and extern if it is declared outside main().
3. Which of the following is not a logical operator?
a) & , b) &&, c) ||, d) !
ans: option a
4. What will be output of the following program?
#include<stdio.h>
void main()
{
int i=3;
i=i++;
printf("%d",i);
}
ans: 4
5. What will be output of the following program?
#include<stdio.h>
void main()
{
int x=4,y,z;
y=--x;
z=x--;
printf("%d %d %d",x,y,z);
}
ans: 2 3 3
6. We want to round off x, a float, to an int value. The correct way to do so will be?
a) y=(int)(x+0.5);
b) y=int(x+0.5);
c) y=(int)x+0.5;
d) y=(int)((int)x+0.5);
ans: option (a)
7. Is it true that too many recursive calls may result into stack overflow?
ans: yes
8. If the size of int is 4 byte , then what will be the output of the program?
#include<stdio.h>
void main()
{
int arr[]={12,13,14,15,16};
printf("%d %d %d",sizeof(arr), sizeof(*arr),sizeof(arr[0]));
}
ans: 20 4 4
9. What will be output of the following program?
#include<stdio.h>
void main()
{
char *str;
str="%d \n";
str++;
str++;
printf(str -2,300);
}
ans: 300
10. What will be output of the following program?
#include<stdio.h>
void main()
{
int i,*j,k;
i=3;
j=&i;
printf("%d",i**j*i+*j);
}
ans:30
No comments:
Post a Comment