Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
Ans: Option C
16 bit compiler requires 2 bytes of storage
#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
#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
#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
#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
#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!
#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
#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
#include <stdio.h>
int main()
{
int ThisIsVariableName = 12;
int ThisIsVariablename = 14;
printf("%d", ThisIsVariablename);
return 0;
}
#include <stdio.h>
int main()
{
printf("Programming\rLab\n");
return 0;
}
a) ProgrammingLab
b) Programming
Lab
c) Labgramming
d) Programming
#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
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
#include <stdio.h>
int main()
{
int var = 010;
printf("%d", var);
}
a) 2
b) 8
c) 9
d) 10
#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
#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
#include <stdio.h>
int main()
{
int i = -3;
int k = i % 2;
printf("%d\n", k);
}
#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}
#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
main()
{
int i = -4, j, num = 10;
j = i%-3;
j = (j ? 0: num * num);
printf ("j = %d",j);
}
#include <stdio.h>
void main()
{
int k = 0;
for (k < 3; k++)
printf("Hello");
}
#include <stdio.h>
int main()
{
int i = 0;
for (; ; ;)
printf("In for loop\n");
printf("After loop\n");
}
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
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 ) ;
}