C Debuggung Questions with Answers

C Debuggung Questions with Answers

C DEBUGGUNG QUESTIONS WITH ANSWERS

1. void main()
{
int const * p=5;
printf("%d", ++(*p));
}

2. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c% c%c%c",s[ i ],*(s+i),*(i+ s),i[s]);
}
3. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}

4. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}

Answer:
5 4 3 2 1
Explanation:
When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.
5. main()
{
int c[ ]={2.8,3.4,4, 6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q;

}
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}
Answer:
2 2 2 2 2 2 3 4 6 5
Explanation:
Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.

6. main()
{
extern int i;
i=20;
printf("%d", i);
}
Answer:
Linker Error : Undefined symbol '_i'
Explanation:
extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .
7. main()
{
int i=-1,j=-1,k= 0,l=2,m;
m=i++&j++&k++||l++;
printf("%d %d %d %d %d",i,j,k,l, m);
}
Answer:
0 0 1 3 1
Explanation :
Logical operations always give a result of 1 or 0 . And also the logical AND (&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ & j++ & k++’ is executed first. The result of this expression is 0 (-1 & -1 & 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1.

8. main()
{
char *p;
printf("%d %d ",sizeof(*p) ,sizeof(p) );
}
Answer:
1 2
Explanation:
The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.
9. main()
{
int i=3;
switch(i)
{
default:printf( "zero");
case 1: printf("one" );
break;
case 2:printf("two" );
break;
case 3: printf("three" );
break;
}
}
Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

10. main()
{
printf("%x", -1<4);
}
Answer:
fff0
Explanation :
-1 is internally represented as all 1's.. When left shifted four times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value.

11. #include * What is wrong in the following problem

main() {
int i,j;
j = 10;
i = j++ – j++;
printf(“%d %d”, i,j);
}
ans: 0, 12

12.#include * What is the output of the following problem
main() {
int j;
for(j=0;j<3;j++)
foo();
}
foo() {
static int i = 10;
i+=10;
printf(“%d\n”,i);
}

/* Out put is (***since static int is used i value is retained between
* 20 function calls )
* 30
* 40
*
/

13.#include #include #include /* This is asked in PCS Bombay walk-in-interview
* What is wrong in the following code
*/
main()
{
char *c;
c = “Hello”;
printf(“%s\n”, c);
}
/*ans:- Hello, The code is successfully running */

14. #include /* This problem is given in PCS BOMBAY walk-in-interview.
* What is the final value of i and how many times loop is
* Executed ?
*/

main()

{
int i,j,k,l,lc=0;
/* the input is given as 1234 567 */
printf(“Enter the number string:<1234 567 \n”);
scanf(“%2d%d%1d”,&i,&j,&k);
for(;k;k–,i++)
for(l=0;lprintf(“%d %d\n”,i,l);}
printf(“LOOPS= %d\n”, lc-1);
}
/* Ans: i = 16, and loop is executed for 169 times */

15.#include /* This is given in PCS Bombay walk-in-interview */
/* What is the output of the following program */

main() {
union {
int a;
int b;
int c;
} u,v;
u.a = 10;
u.b = 20;
printf(“%d %d \n”,u.a,u.b);
}
/* Ans : The latest value assigned to any of the union member
will be present in the union members so answer is
20 20
*/

16.#include main()
{
float i, j;
scanf(“%f %f”, &i, &j);
printf(“%.2f %.3f”, i, j);
}

/Ans:- 123.34 3. 234 */

17.#include /* This is given in PCS Bombay walk-in-interview
* What is the out put of the following problem ?
*/

main()
{
char *str = “12345″;
printf(“%c %c %c\n”, *str, *(str++), *(str++));
}
/* Ans: It is not 1 2 3
* But it is 3 2 1 Why ??
*/

18.#include /* This problem is asked in PCS Bombay Walk-in-interview
* Write a macro statement to find maximum of a,b
*/
#define max(a,b) (ab)?a:b
main()
{
int a,b;
a=3;
b=4;
printf(“%d”,max(a,b));
}
/* Ans is very simple the coding is just for testing it
and output is 4 */

~

19.#include /* This problem is asked in PCS Bombay
* What is the output of the following coding
*/

main()
{
int len=4;
char *st=”12345678″;
for(i=0; i<6; i++)
st = st -len;
printf(“%c\n”,*st);
}
/* Ans : It will print some junk value */

20.#include main()
{
func(1);
}
func(int i){
static char *str ={ “One”,”Two”,”Three”,”Four”};
printf(“%s\n”,str[i++]);
return;
}
/* Ans:- it will give warning because str is pointer to the char but
it is initialized with more values
if it is not considered then the answer is Two */

21)#include main()
{
int i;
for (i=1;i<100; i++)
printf(“%d %0x\n”,i,i);
}
/* Ans:- i is from 1 to 99 for the first format,
for the second format 1to9, ato f, 10 to 19,1ato1f, 20 to 29, etc */

22.#include /* This problem is asked in PCS Bombay walk-in-interview
* In the following code please write the syntax for
* assing a value of 10 to field x of s and id_no 101 of s
*/
struct {
int x;
int y;
union {
int id_no;
char *name;
}b;
}s,*st;
main()
{
st = &s;
st-x=10;
st-b.id_no = 101;
printf(“%d %d\n”,s.x,s.b.id_no);
}
/* Ans: The answer is st-x=10;
* st-b.id_no=101;
*/

23)#include /* This problem was asked in PCS Bombay in a walk-in-interview
* Write a recursive function that calculates
* n * (n-1) * (n-2) * ……. 2 * 1
*/

main() {
int factorial(int n);
int i,ans;
printf(“\n Enter a Number:”);
scanf(“%d”,&i);
ans = factorial(i);
printf(“\nFactorial by recursion = %d\n”, ans);
}
int factorial(int n)
{
if (n <= 1) return (1);
else
return ( n * factorial(n-1));
}

~

24)#include /* This problem is asked in PCS Bombay walk-in-interview
* What is the output of the following problem
*/
main(){
int j,ans;
j = 4;
ans = count(4);
printf(“%d\n”,ans);
}
int count(int i)
{
if ( i < 0) return(i);
else
return( count(i-2) + count(i-1));
}

/* It is showing -18 as an answer */

25.#includemain()
{
int i=4;
if(i=0)
printf(“statement 1″);
else
printf(“statement 2″);
}
/* statement 2 */

26. What will be the value of variable a in the following code?
unsigned char a;
a = 0xFF + 1;
printf(“%d”, a);
0 <——ans

27. What is the output of the following program?
#include
void main()
{
printf(“\n10!=9 : %5d”,10!=9);
}
1<——ans

28. #include
void main()
{
int x=10;
(x<0)?(int a =100):(int a =1000);
printf(” %d”,a);
}

Error<——ans

29) int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b/a;

What number will z in the sample code above contain?
a) 5
b) 6
c) 10

d) 11

Ans: c

30) void *ptr; myStruct myArray[10]; ptr=myArray;

Which of the following is the correct way to increment the variable "ptr"?
a) ptr = ptr + sizeof(myStruct);
b) ++(int*)ptr;
C)ptr = ptr + sizeof(myArray);
d) ptr = ptr + sizeof(ptr);

Ans: a

31) int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
a) 3
b) 7
C) 9
d) 11

Ans: d

32) void mmyFunc(int x) { if(x>0) myFunc(--x); } int main() { myFunc(5); return 0;}

What will the above sample code produce when executed?
a) 4, 3, 2, 1, 0, 0,
b) 5, 4, 3, 2, 1, 0,
C) 0, 0, 1, 2, 3, 4,
d) 0, 1, 2, 3, 4, 5,

Ans: c

33) main()
{
char not;
not=!2;
printf("%d",not);
}

a)2 b)error c) 0 d)1

ANS: c

34) int i,j;
for (i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}

a) Compile time error b) runtime error c) not error d) error

ans: b

35) main()
{
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n];
for(i=0; i
{
printf(“%s\n”,x);
x++;
}
}
a) blank space b) irl c) rl d) l e) all the above

Ans: e

36) main()
{
extern out;
printf("%d", out);
}
int out=100;

a) declaration error b) 100 c) runtime error d) none

ans : b

37) main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}

a) a b) b c) M d) c

ans: c

38) void main()

{ unsigned i=1; /* unsigned char k= -1 => k=255; */ signed j=-1; /* char k= -1 => k=65535 */ /* unsigned or signed int k= -1 =>k=65535 */ if(ij) printf("greater"); else if(i==j) printf("equal"); }

a)less b)greater c) equal d) none of the

ans) less

39 )What can go wrong if you replace & with & in the following code:
String a=null;
if(a!=null & a.length()>10)

{…}

a)Null pointer Exception
b)compile time error
c)Run time error

d)code runs successfully

ans)Null pointer Exception

40) #include void fun(int **p); int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; int *ptr; ptr = &a[0][0]; fun(&ptr); return 0; } void fun(int **p) { printf("%d\n", **p); } What will be the output of the program ?

a)1 b)2 c)3 d)4

ans)1

41)#include #include int main() { char *ptr; *ptr = (char)malloc(30); strcpy(ptr, "RAM");

printf("%s", ptr); free(ptr); return 0; } Point out the error in the following program.

a)Error: in strcpy() statement.b)Error: in *ptr = (char)malloc(30);c)Error: in free(ptr);d)No error

ans)Error: in *ptr = (char)malloc(30);

42 ) #include int main() { struct s1 { char *z; int i; struct s1 *p; }; static struct s1 a[] = {{"Nagpur", 1, a+1} , {"Chennai", 2, a+2} , {"Bangalore", 3, a} }; struct s1 *ptr = a; printf("%s,", ++(ptr->z)); printf(" %s,", a[(++ptr)->i].z); printf(" %s", a[--(ptr->p->i)].z); return 0; } What will be the output of the program?

a) Nagpur, Chennai, Bangalore b) agpur, hennai, angalore c) agpur, Chennai, angalore d) agpur, Bangalore, Bangalore ans) agpur, Bangalore, Bangalore Your ans) Mark= 0

43 ) #include int fun(int(*)()); int main() { fun(main); printf("Hi\n"); return 0; } int fun(int (*p)()) { printf("Hello"); return 0; } What will be the output of the program?

a) Infinite loop b) Hi c) Hello Hi d) Error ans) Hello Hi Your ans) Mark= 0

44 ) #include int main() { int arr[]={2, 3, 4, 1, 6}; printf("%u, %u, %u\n", arr, &arr[0], &arr); return 0; } What will be the output of the program if the array begins 1200 in memory?

a) 1200, 1202, 1204 b) 1200, 1200, 1200 c) 1200, 1204, 1208 d) 1200, 1202, 1200 ans) 1200, 1200, 1200 Your ans) Mark= 0

45 ) #include int main() { int i; char c; for(i=1; i<=5; i++) { scanf("%c", &c); /* given input is 'b' */ ungetc(c, stdout); printf("%c", c); ungetc(c, stdin); } return 0; } What will be the output of the program?

a) bbbb b) bbbbb c) b d) Error in ungetc statement. ans) b Your ans) Mark= 0

46 ) #include int main() { char far *near *ptr1; char far *far *ptr2; char far *huge *ptr3; printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3)); return 0; } What will be the output of the program?

a) 4, 4, 8 b) 4, 4, 4 c) 2, 4, 4 d) 2, 4, 8 ans) 2, 4, 4 Your ans) Mark= 0

47 ) #include int main(int argc, char *argv, char *env[]) { int i; for(i=1; i

a) List of all environment variables b) List of all command-line arguments c) count of command-line arguments d) Error: cannot have more than two arguments in main( ans) List of all environment variables Your ans) Mark= 0

48 ) #include int main() { enum status {pass, fail, absent}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = absent; stud3 = fail; printf("%d %d %d\n", stud1, stud2, stud3); return 0; } What will be the output of the program ?

a)0,1,2b)1,2,3c)0,2,1d)1,3,2ans)0,2,1

49 ) #include int main() { char *s; char *fun(); s = fun(); printf("%s\n", s); return 0; } char *fun() { char buffer[30]; strcpy(buffer, "RAM"); return (buffer); } What will be the output of the program?

a) 0xffff b) Garbage value c) 0xffee d) Error ans) Garbage value Your ans) Mark= 0

50 ) What is x in the following program? #include int main() { typedef char (*(*arrfptr[3])())[10]; arrfptr x; return 0; }

a) x is a pointer b) x is an array of three pointer c) x is an array of three function pointers d) Error in x declaration ans) x is an array of three function pointers Your ans) Mark= 0

51 ) #include int main() { typedef int LONG; LONG a=4; LONG b=68; float c=0; c=b; b+=a; printf("%d,", b); printf("%f\n", c); return 0; } What will be the output of the program?

a) 72, 68.000000 b) 72.000000, 68 c) 68.000000, 72.000000 d) 68, 72.000000 ans) 72, 68.000000 Your ans) Mark= 0

52 ) #include #define SQR(x)(x*x) int main() { int a, b=3; a = SQR(b+2); printf("%d\n", a); return 0; } What will be the output of the program?

a) 25 b) 11 c) error d) garbage value ans) 11 Your ans) Mark= 0

53 ) Can you combine the following two statements into one? char *p; p = (char*) malloc(100);

a) char p = *malloc(100); b) char *p = (char) malloc(100); c) char *p = (char*)malloc(100); d) char *p = (char *)(malloc*)(100); ans) char *p = (char*)malloc(100); Your ans) Mark= 0

54 ) #include int main() { unsigned int a=0xffff; ~a; printf("%x\n", a); return 0; } If an unsigned int is 2 bytes wide then, What will be the output of the program ?

a) ffff b) 0000 c) 00ff d) ddfd ans) ffff

55 ) #include int main() { float a=0.7; if(a < 0.7f) printf("C\n"); else printf("C++\n"); return 0; } What will be the output of the program?

a) C b) C++ c) Compiler Error d) None of the above ans) C++ Your ans) Mark= 0

56 ) #include #include int main() { printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l)); return 0; } What will be the output of the program?

a) 4, 4, 4 b) 4, 8, 8 c) 4, 8, 10 d) 4, 8, 12 ans) 4, 8, 10

57 ) #include int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit; printf("%d\n", sizeof(bit)); return 0; } What will be the output of the program ?

a) 1 b) 2 c) 4 d) 9 ans) 2 Your ans) Mark= 0

58 ) #include int main() { char str[20] = "Hello"; char *const p=str; *p='M'; printf("%s\n", str); return 0; } What will be the output of the program ?

a) Mello b) Hello c) HMello d) MHello ans) Mello Your ans) Mark= 0

59 ) How many times the program will print "CCET" ? #include int main() { printf("CCET"); main(); return 0; }

a) Infinite times b) 32767 times c) 65535 times d) Till stack doesn't overflow ans) Till stack doesn't overflow

60) long factorial (long x)

{

????

return x * factorial(x - 1);

}

With what do you replace the ???? to make the function shown above return the correct answer?
Choice 1
if (x == 0) return 0;
Choice 2
return 1;
Choice 3
if (x >= 2) return 2;
Choice 4
if (x == 0) return 1;
Choice 5
if (x <= 1) return 1; [Ans]{more probable}

61) Code:

FILE *f = fopen( fileName, "r" );

readData( f );

if( ???? )

{

puts( "End of file was reached" );

}

Which one of the following can replace the ???? in the code above to determine if the end of a file has been reached?
Choice 1
f == EOF [Ans]
Choice 2
feof( f )
Choice 3
eof( f )
Choice 4
f == NULL
Choice 5
!f

62) Code:

char * dwarves [] = {

"Sleepy",

"Dopey" "Doc",

"Happy",

"Grumpy" "Sneezy",

"Bashful",

};

How many elements does the array dwarves (declared above) contain? Assume the C compiler employed strictly complies with the requirements of Standard C.
Choice 1
4
Choice 2
5 [Ans]
Choice 3
6
Choice 4
7
Choice 5
8

63) Code:

char *buffer = "0123456789";

char *ptr = buffer;

ptr += 5;

printf( "%s\n", ptr );

printf( "%s\n", buffer );

What will be printed when the sample code above is executed?
Choice 1
0123456789
56789
Choice 2
5123456789
5123456789
Choice 3
56789
56789
Choice 4
0123456789
0123456789
Choice 5
56789
0123456789 [Ans]

64) Code:

int x[] = {1, 2, 3, 4, 5};

int u;

int *ptr = x;

????

for( u = 0; u < 5; u++ )

{

printf("%d-", x[u]);

}

printf( "\n" );
Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?
Choice 1
*ptr + 3 = 10;
Choice 2
*ptr[ 3 ] = 10;
Choice 3
*(ptr + 3) = 10; [Ans]
Choice 4
(*ptr)[ 3 ] = 10;
Choice 5
*(ptr[ 3 ]) = 10;

65) Code:

#include <stdio.h>

void func()

{

int x = 0;

static int y = 0;

x++; y++;

printf( "%d -- %d\n", x, y );

}

int main()

{

func();

func();

return 0;

}

What will the code above print when it is executed?
Choice 1
1 -- 1
1 -- 1
Choice 2
1 -- 1
2 -- 1
Choice 3
1 -- 1
2 -- 2
Choice 4
1 -- 0
1 -- 0
Choice 5
1 -- 1
1 -- 2 [Ans]

66) Code:

int fibonacci (int n)

{

switch (n)

{

default:

return (fibonacci(n - 1) + fibonacci(n - 2));

case 1:

case 2:

}

return 1;

}

The function above has a flaw that may result in a serious error during some invocations. Which one of the following describes the deficiency illustrated above?
Choice 1
For some values of n, the environment will almost certainly exhaust its stack space before the calculation completes.
[Ans]
Choice 2
An error in the algorithm causes unbounded recursion for all values of n.
Choice 3
A break statement should be inserted after each case. Fall-through is not desirable here.
Choice 4
The fibonacci() function includes calls to itself. This is not directly supported by Standard C due to its unreliability.
Choice 5
Since the default case is given first, it will be executed before any case matching n.

67) Code:

int i = 4;

int x = 6;

double z;

z = x / i;

printf("z=%.2f\n", z);

What will print when the sample code above is executed?
Choice 1
z=0.00
Choice 2
z=1.00[Ans]
Choice 3
z=1.50
Choice 4
z=2.00
Choice 5
z=NULL

68) penny = one
nickel = five
dime = ten
quarter = twenty-five
How is enum used to define the values of the American coins listed above?
Choice 1
enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)};
Choice 2
enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25});
Choice 3
enum coin {penny=1,nickel=5,dime=10,quarter=25};[Ans]
Choice 4
enum coin (penny=1,nickel=5,dime=10,quarter=25);
Choice 5
enum coin {penny, nickel, dime, quarter} (1, 5, 10, 25);

69) Code:

int y[4] = {6, 7, 8, 9};

int *ptr = y + 2;

printf("%d\n", ptr[ 1 ] ); /*ptr+1 == ptr[1]*/

What is printed when the sample code above is executed?
Choice 1
6
Choice 2
7
Choice 3
8
Choice 4
9[Ans]
Choice 5
The code will not compile.

70) Code:

int x = 0;

for ( ; ; )

{

if (x++ == 4)

break;

continue;

}

printf("x=%d\n", x);

What will be printed when the sample code above is executed?
Choice 1
x=0
Choice 2
x=1
Choice 3
x=4
Choice 4
x=5 [Ans]
Choice 5
x=6

71)Code:

int i = 4;

switch (i)

{

default:

;

case 3:

i += 5;

if ( i == 8)

{

i++;

if (i == 9) break;

i *= 2;

}

i -= 4;

break;

case 8:

i += 5;

break;

}

printf("i = %d\n", i);

What will the output of the sample code above be?
Choice 1
i = 5[Ans]
Choice 2
i = 8
Choice 3
i = 9
Choice 4
i = 10
Choice 5
i = 18

72)Code:

#include <stdio.h>

int i;

void increment( int i )

{

i++;

}

int main()

{

for( i = 0; i < 10; increment( i ) )

{

}

printf("i=%d\n", i);

return 0;

}

What will happen when the program above is compiled and executed?
Choice 1
It will not compile.
Choice 2
It will print out: i=9.
Choice 3
It will print out: i=10.
Choice 4
It will print out: i=11.
Choice 5
It will loop indefinitely.[Ans]

73) Code:

short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} };

printf( "%d\n", sizeof( testarray ) );

Assuming a short is two bytes long, what will be printed by the above code?
Choice 1
It will not compile because not enough initializers are given.
Choice 2
6
Choice 3
7
Choice 4
12
Choice 5
24 [Ans]

74) struct customer *ptr = malloc( sizeof( struct customer ) );

Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?
Choice 1
ptr = realloc( ptr, 10 * sizeof( struct customer)); [Ans]
Choice 2
realloc( ptr, 9 * sizeof( struct customer ) );
Choice 3
ptr += malloc( 9 * sizeof( struct customer ) );
Choice 4
ptr = realloc( ptr, 9 * sizeof( struct customer ) );
Choice 5
realloc( ptr, 10 * sizeof( struct customer ) );

75)char ** array [12][12][12];
Consider array, defined above. Which one of the following definitions and initializations of p is valid?
Choice 1
char ** (* p) [12][12] = array; [Ans]
Choice 2
char ***** p = array;
Choice 3
char * (* p) [12][12][12] = array;
Choice 4
const char ** p [12][12][12] = array;
Choice 5
char (** p) [12][12] = array;

76)void (*signal(int sig, void (*handler) (int))) (int);
Which one of the following definitions of sighandler_t allows the above declaration to be rewritten as follows:
sighandler_t signal (int sig, sighandler_t handler);
Choice 1
typedef void (*sighandler_t) (int);[Ans]
Choice 2
typedef sighandler_t void (*) (int);
Choice 3
typedef void *sighandler_t (int);
Choice 4
#define sighandler_t(x) void (*x) (int)
Choice 5
#define sighandler_t void (*) (int)

77)Code:

x = 3, counter = 0;

while ((x-1))

{

++counter;

x--;

}

Referring to the sample code above, what value will the variable counter have when completed?
Choice 1
0
Choice 2
1
Choice 3
2[Ans]
Choice 4
3
Choice 5
4

78) Code:

int x = 5;

int y = 2;

char op = '*';

switch (op)

{

default : x += 1;

case '+' : x += y; /*It will go to all the cases*/

case '-' : x -= y;

}

After the sample code above has been executed, what value will the variable x contain?
Choice 1
4
Choice 2
5
Choice 3
6 [Ans]
Choice 4
7
Choice 5
8

79) Code:

double x = -3.5, y = 3.5;

printf( "%.0f : %.0f\n", ceil( x ), ceil( y ) );

printf( "%.0f : %.0f\n", floor( x ), floor( y ) );

What will the code above print when executed?
ceil =>rounds up 3.2=4 floor =>rounds down 3.2=3
Choice 1
-3 : 4
-4 : 3 [Ans]
Choice 2
-4 : 4
-3 : 3
Choice 3
-4 : 3
-4 : 3
Choice 4
-4 : 3
-3 : 4
Choice 5
-3 : 3
-4 : 4