Department of Computer Science & Engineering
CS102 Programming for Problem Solving Lab
Class: B.Tech. (CSE) Section: C Session: SP/19
Roll No: Name:
1. What will be output when you will execute following c code?
#define PRINT printf ("Star Wars"); printf (" Psycho");
#include<stdio.h>
Void main () {
int x=1;
If(x--)
PRINT
Else
Printf ("The Shawshank Redemption"); }
(A) Stars Wars Psycho (C) Warning: Condition is always
true
(B) The Shawshank Redemption (E) Compilation error
2. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
int a=10;
if(printf("%d",a>=10)-10)
for(;;)
break;
else; }
(A It will print nothing (C) 0
(B) 1 (E) Compilation error
3. What would be the output of the following program, if the array begins at address 1200?
Main()
{ int arr[]={2,3,4,1,6};
Printf(“%d%d”, arr, sizeof(arr)); }
Ans-----------------------
4. What would be the output of the following program?
Main ()
{Char a[]= “C program”;
Char *b= “C program”;
Printf(“%d%d\n”, sizeof(a), sizeof(b));
Printf(“%d%d\n”, sizeof(*a), sizeof(*b));
}
Ans-----------------------
5. What would be the output of following program?
Main()
{ char str1[]= “Hello”;
char str2[]= “Hello”;
if(str1==str2)
printf(“\n equal”);
else
printf(“\n unequal”);
}
Ans------------------
6. What will be the output of the following C program segment?
char inchar = 'A';
switch (inchar)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ; }
Ans------------------
7. Consider the following C function:
int f(int n)
{
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
}The value returned by f(1) is
Ans------------------
8. Point out error, if any, in the following function.
main ()
{ int b;
b= f(20);
printf(“%d”, b); }
Int f (int a)
{ a>20? return (10): return (20) ;}
Ans------------------
9. What would be the output of following program?
#define SQR(x) (x*x)
Int main ()
{ int a, b=3;
a= SQR(b+2);
printf(“\n%d”,a); }
Ans------------------
10. What would be the output of following program?
Main ()
{inc(); inc(); inc(); }
Inc()
{Static int x;
Printf(“%d”, ++x); }
Ans------------------