Question On Datatypes
Question On Datatypes
Question On Datatypes
Suppose a C program has floating constant 1.414, what's the best way to convert this as "float" data
type?
A (float)1.414
B float(1.414)
C 1.414f or 1.414F
Question 2
#include<stdio.h>
int main(){
volatile int a=11;
printf("%d",a);
return 0;
}
Question 3
“typedef” in C basically works as an alias. Which of the following is correct for “typedef”?
A typedef can be used to alias compound data types such as struct and union.
B typedef can be used to alias both compound data types and pointer to these compound types.
signed s;
unsigned u;
long l;
Run on IDE
A All of the above variable definitions are incorrect because basic data type int is missing.
B All of the above variable definitions are correct because int is implicitly assumed in all of these.
C Only “long l;” and “long long ll;” are valid definitions of variables.
Question5
Predict the output of following program. Assume that the numbers are stored in 2's complement
form.
#include<stdio.h>
int main()
int y = ~0;
if (x == y)
printf("same");
else
printf("not same");
return 0;
A Same
not same
B
The correct answer is A.
Question 6
1. short int x;
Run on IDE
2. signed short x;
Run on IDE
3. short x;
Run on IDE
4. unsigned short x;
A 3 and 4
B 2
C 1
Question 7
#include <stdio.h>
int main()
float c = 5.0;
return 0;
Compiler Error
D
The correct answer is B
Question 8
#include <stdio.h>
int main()
char a = '12';
printf("%d", a);
return 0;
Run on IDE
A Compiler Error
B 12
C 10
D Empty
Question 9
A True
B False
Question 10
Output?
int main()
void *vptr, v;
v = 0;
vptr = &v;
printf("%v", *vptr);
getchar();
return 0;
Run on IDE
A 0
B Compiler Error
C Garbage Value
Question 11
Assume that the size of char is 1 byte and negatives are stored in 2's complement form
#include<stdio.h>
int main()
char c = 125;
c = c+10;
printf("%d", c);
return 0;
Run on IDE
A 135
B +INF
C -121
D -8
#include <stdio.h>
int main()
printf("Yes");
else
printf("No");
return 0;
Run on IDE
A Yes
B No
C Compiler Error
D Runtime Error
Question 13
Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large,
which of the following statements is most likely to set p correctly?
A p = n * (n-1) * (n-2) / 6;
B p = n * (n-1) / 2 * (n-2) / 3;
C p = n * (n-1) / 3 * (n-2) / 2;
Question 14
#include<stdio.h>
int main()
{
float x = 0.1;
if ( x == 0.1 )
printf("IF");
else if (x == 0.1f)
printf("ELSE IF");
else
printf("ELSE");
A ELSE IF
B IF
ELSE
C
The correct answer is A.
15. What is the size of an int data type?
● A. 4 Bytes
● B. 8 Bytes
● C. Depends on the system/compiler
● D. Cannot be determined.
16. Which data type is most suitable for storing a number 65000 in a 32-bit system?
● A. short
● B. int
● C. long
● D. double
int main()
{
int a[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
if ((char)a[i] == '5')
printf("%d\n", a[i]);
else
printf("FAIL\n");
}
Answer: Option D
Explanation:
The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
$ cc pgm1.c
$ a.out
FAILED
FAILED
FAILED
FAILED
FAILED
#include<stdio.h>
int main(){
int a= sizeof(signed) +sizeof(unsigned);
int b=sizeof(const)+sizeof(volatile);
printf("%d",a+++b);
return 0;
}