Sei sulla pagina 1di 12

14EC320 – PROBLEM SOLVING USING COMPUTERS

TUTORIAL - 2

1. The format identifier ‘%i’ is also used for _____ data type?
a) char
b) int
c) float
d) double

Ans: option b. %i used for denoting integer which includes decimal, octal and hexadecimal
representations.

2. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int
Ans: option b.
Signed int: Range between -32768 to 32767
Unsigned int ranges between 0 to 65536.
long Ranges -2147483648 to 2147483647
Int Ranges -2147483648 to 2147483647

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

Ans: Option C
16 bit compiler requires 2 bytes of storage

4. What is the output of this C code?

#include <stdio.h>
int main()
{
signed char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}

a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned

5. 8. What is short int in C programming?


a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic datatype
d) All of the mentioned

6. Comment on the output of this C code?

#include <stdio.h>
int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf("equal\n");
else
printf("not equal\n");
}

a) equal
b) not equal
c) Output depends on compiler
d) None of the mentioned

7. Comment on the output of this C code?

#include <stdio.h>
int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf("equal\n");
else
printf("not equal\n");
}

a) equal
b) not equal
c) Output depends on compiler
d) None of the mentioned

8. What is the output of this C code?

#include <stdio.h>
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}

a) a
b) run time error
c) a.0000000
d) 97.000000
9. Which of the following is not a valid variable name declaration?
a) int __a3;
b) int __3a;
c) int __A3;
d) None of the mentioned
10. Which of the following is not a valid variable name declaration?
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a

11. Variable names beginning with underscore is not encouraged. Why?


a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
12. Which of the following is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;
13. Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;
14. What is the output of this C code?

#include <stdio.h>
int main()
{
printf("Hello World! %d \n", x);
return 0;
}

a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!

15. What is the output of this C code?

#include <stdio.h>
int main()
{
int y = 10000;
int y = 34;
printf("Hello World! %d\n", y);
return 0;
}
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value

16. Which of the following is not a valid variable name declaration?


a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14
17. What will happen if the below program is executed?

#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}

a) It will cause a compile-time error


b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping

18. What is the problem in following variable declaration?


float 3Bedroom-Hall-Kitchen?;
a) The variable name begins with an integer
b) The special character ‘-‘
c) The special character ‘?’
d) All of the mentioned

19. Comment on the output of this C code?

#include <stdio.h>
int main()
{
int ThisIsVariableName = 12;
int ThisIsVariablename = 14;
printf("%d", ThisIsVariablename);
return 0;
}

a) The program will print 12


b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time error due to redeclaration

20. Which of the following cannot be a variable name in C?


a) volatile
b) true
c) friend
d) export
21. What is the output of this C code?

#include <stdio.h>
int main()
{
printf("Programming\rLab\n");
return 0;
}
a) ProgrammingLab
b) Programming
Lab
c) Labgramming
d) Programming

22. What is the output of this C code?

#include <stdio.h>
int main()
{
const int p;
p = 4;
printf("p is %d", p);
return 0;
}

a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value

23. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a. short
b. int
c. long
d. double

24. 24.Comment on the output of this C code?

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");
}
A. The compiler will flag an error
B. Program will compile and print the output 5
C. Program will compile and print the ASCII value of 5
D. Program will compile and print FAIL for 5 times

25. What is the output of this C code?

#include <stdio.h>
int main()
{
int var = 010;
printf("%d", var);
}

a) 2
b) 8
c) 9
d) 10

26. What is the output of this C code?

#include <stdio.h>
#define MAX 2
enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
int main()
{
enum bird b = PARROT;
printf("%d\n", b);
return 0;
}

a) Compilation error
b) 5
c) Undefined value
d) 2

27. Comment on the output of this C code?

#include <stdio.h>
void main()
{
int const k = 5;
k++;
printf("k is %d", k);
}

a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed

28. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = -3;
int k = i % 2;
printf("%d\n", k);
}

a) Compile time error


b) -1
c) 1
d) Implementation defined

29. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}

a) Compile time error


b) -1 1
c) 1 -1
d) Implementation defined

30. What is the output of this C code?

#include <stdio.h>
void main()
{
float x = 5.3, y;
y= x % 2;
printf("Value of x is %f", y);
}

a) Value of x is 2.3
b) Value of x is 1
c) Value of x is 0.3
d) Compile time error

31. Find the output


main()
{
int x = 3, y = 4, z = 4;
printf("ans = %d", (z>=y>=x?100:200));
}

32. Find the output

main()
{
int i = -4, j, num = 10;
j = i%-3;
j = (j ? 0: num * num);
printf ("j = %d",j);
}

33. What is the output of this C code?

#include <stdio.h>
void main()
{
int k = 0;
for (k < 3; k++)
printf("Hello");
}

a) Compile time error


b) Hello is printed thrice
c) Nothing
d) Varies

34. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = 0;
for (; ; ;)
printf("In for loop\n");
printf("After loop\n");
}

a) Compile time error


b) Infinite loop
c) After loop
d) Undefined behaviour

35.
extern int x;
int main()
{
do
{
do
{
Printf(“%o”, x);
}while(!-2);
}while(0);
Return(0);
}
x=8;
a. 8
b. 10
c. Vary from complier
d. Linker error: undefined symbol

36.
main()
{
int i=3, j=3;
while(i+1 ? –i:++i)
printf(“%d \t%d”,i,j);
}

a. 2 3
1 2
b. 1 2
2 1
c. 2 3
1 3
d. 3 3
2 2

37.
main( )
{
if(!printf(“%d”, printf(“Computer”)))
printf(“ books”);
else
printf(“ science”);
}
a. 8computer books
b. 8computer science
c. computer8 books
d. computer8 science

38. Find the output

main() {
int x = 10, y = 20;
if (! (!x) && x)
printf ("x = %d",x);
else
printf ("y = %d",y);
}

39. What will be the output of the following programs and justify the output:
main ()
{
char j = 1 ;
while ( j < = 255) {
printf ("%d\n",j);
j=j+1;
}
}

40. main()
{
intj = 1 ;
while ( j <= 2 5 5 ) ;
{
printf ("%c%d\n",j,j);
}
}

41. main()
{
inti = 1, j = 1 ;
for ( ; j ; printf (“%d%d\n” i,j))
j = i++ < = 5 ;
}

42.
main()
{
int i = 1 ;
for {; i++;)
printf ( " % d i ) ;
}

43.
main()
{
int a = 5 ;
do
{
printf ("%d\n", a ) ; a = - 1 ;
}while(a>0);

44.
main()
{
intx = 3 , z ;
z = x++ + x++;
,
printf ("x = %dz = %d , x , z ) ;
}

45.
main()
{
int x = 3, z ;
z = x++ + ++x;
printf ("x = %dz = %d", x , z ) ;
}

46.
main()
{
int x = 10, y, z ;
z=y=x;
y-= x--;
z -= --x;
x -= --x - x - ;
printf ("y = %d z = %d x = %d", y, z, x ) ;
}

47.
main()
{
intx,y,z;
x=y=z=1;
z =++x &&++y &&++z;
printf ("x = %d y = %d z = %d\n", x, y, z ) ;
}

48.
main()
{
int x, y, z ;
x=y=z=-1;
z = ++x && ++y || ++z;
printf ("x = %dy = %dz = %d\n",x,y,z);
}

49.
main()
{
i
int i ;
for (i = - 1 ; i <= 10; i++)
{
if(i<5)
continue;
else
break;
printf ("Gets printed only once!!");
}
}

50.
#define CUBE(X) ( X * X * X )
main()
{
int a, b; b = 3 ;
a = CUBE(b++)/b++;
printf ("a = %db = %d", a, b ) ;
}

51.
#define ISLOWER(a) ( a >= 97 && a <= 127)
#define TOUPPER(a) ( a - 3 2 )
main()
{
char ch = 'c';
if (ISLOWER(ch))
ch = TOUPPER(ch);
printf ("%c", c h ) ;
}

Potrebbero piacerti anche