CDS S13
CDS S13
C- PROGRAMMING LANGUAGE
SOLUTIONS
main ( )
{
int i = 5;
if (i = = 5) return;
else printf “i is not five”);
printf (“over”);
}
results in
main ( )
{
int x = 2, y = 2;
if (x<y) return (x = x+y);
else printf (“z1”);
printf (“z1”);
printf (“z2”);
}
(a) The scope of a macro definition need not be the entire program
(b) The scope of a macro definition extends from the point of definition to the end of the file
(c) A macro definition may go beyond a line
(d) None of the above
if (a>b)
printf (“a>b”)
else
printf (“else part”);
printf (“a<=b”);
then a <= b
will be printed if
void *voidPtr;
char *charPtr;
3
Solution: Option (b)
main ( )
{
static int x[ ] = {1, 2, 3, 4, 5, 6, 7, 8};
inti ;
for (i = 2; i<6; ++i)
x [x[i]] = x [i];
for (i = 0; i<8; ++i)
printf (“%d”, x [i]);
}
main ( )
{
static char [3] [4] = {“abcd”, “mnop”, “fghi”};
putchar (**a);
}
#include<stdio.h>
4
main ( )
{
int abc ( );
abc ( );
(*abc) ( );
}
int abc ( )
{ printf (“come”);}
char x [ ] = “SUCCESS”;
char *y = “SUCCESS”;
(a) The output of puts (x) and puts (y) will be different
(b) The output of puts (x) and puts (y) will be same
(c) The output of puts (y) is implementation dependent
(d) None of the above comments are true
(a) Finds the hypotenuse of a triangle with sides a+2 and b+3
(b) Finds the square root of (a+2)2 + (b+3)2
(c) Finds the square root of 3*a + 4*b + 5
(d) Is invalid
Solution: Option ( c )
Explanation:
6
Solution: Option (d)
main ( )
{
int a = 1, b = 2, c = 3;
printf (“%d”, a+ = (a+ = 3, 5, a));
}
will be
(a) 12 (b) 6
(c) 9 (d) 8