C- Functions Question and Answer

C- Functions Question and Answer
31. Which of the following would compute the square of x in C?
  • pow (2, x);
  • pow (x, 2)
  • x**2
  • power (x, 2)
Show Answer
32. All Standard C library <math.h> functions return data type ?
  • decimal
  • float
  • double
  • int
Show Answer
33. void show ( ) ;
main ( )
{
show ( );
}
void show ( char *s)
{
printf ("%s\n", s);
}
What will happen when the above code is compiled and executed using a strict ANSI C compiler ?
  • it will compile and nothing will be printed when it is executed.
  • It will compile, but not link.
  • the compiler will generate an error.
  • the compiler will generate a warning.
Show Answer
34. void display (int x)
{
if (x ! = 0)
{
display (x/16);
putchar ("0123456789ABCDEF" [x % 16]);
}
else
putchar ('\n');
}
What will be output if the above function is called with x = 1234?

  • 1234
  • 4321
  • 4D2
  • It will not compile
Show Answer
35. int i =3, a=1, b=1;
void func( )
{
int a =0;
static int b = 0;
a++; b++;
}
int main ( )
{
for ( i = 0, i < 5; i++)
{
func ( ) ;
a++; b++;
}
printf ("a=%d b =%d\n", a, b);
What will be printed from the sample code above ?
  • a=0 b=6
  • a=5=5
  • a=5 b=6
  • a=6 b=6
Show Answer
36. long factorial (long  x)
{
????
return x * factorial (x-1);
}
What would you replace the ???? with, to make the function shown above, return the correct answer ?
  • if (x ==0) return 0;
  • if (x==0) return 1;
  • if (x<=1)return 1;
  • return 1;
Show Answer
37. if (x ? y : z) do something ( );
Refering to the sample above, which statement correctly identifies when y is evaluated ?


  • y is evaluated only when x = = 1
  • y is evaluated only when x >=1.
  • y is evaluated only when x!=0
  • y is evaluated only when x==0.
Show Answer
38. const int var1 = 1;
static int var2 = 2;
void func ( )
{
int var 3 = 3;
static int var 4 = 4;
}
Which of the above variables exist after the function returns and cannot be accessed fromanother file ?
  • var 2 only
  • var4 only
  • var 2 and var 4 only
  • var 2, var3, and var4 only
Show Answer
39. void func (int x)
{
if (x > 0) func (--x);
printf ("%d, ", x);
}
int main ( )
{
func (5);
return 0;
}
what will the above sample code produce when executed ?
  • 0, 1, 2, 3, 4, 5
  • 0, 0, 1, 2, 3, 4
  • 4, 3, 2, 1, 0
  • 5, 4, 3, 2, 1, 0
Show Answer
40. # include <stdio.h>
void show ( )
{
printf ( ("Water\n");
}
/* main. c */
#include <stdio.h>
static void show ( )
{
printf ("Drink\n");
int main ( )
{
show ( );
return 0;
}
Referring to the program given by the 2 source files defined in the code above, what will happen when you try to build and run the program?

  • it will print Water
  • It will print Drink.
  • It will print:
  • Drink water
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test