C Functions Questions and Answers

Practice Mode
Showing 10 of 151 questions
Q31
Which of the following would compute the square of x in C?
  • A pow (2, x);
  • B pow (x, 2)
  • C x**2
  • D power (x, 2)
Answer: Option B
Q32
All Standard C library <math.h> functions return data type ?
  • A decimal
  • B float
  • C double
  • D int
Answer: Option C
Q33
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 ?
  • A it will compile and nothing will be printed when it is executed.
  • B It will compile, but not link.
  • C the compiler will generate an error.
  • D the compiler will generate a warning.
Answer: Option A
Q34
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?
  • A 1234
  • B 4321
  • C 4D2
  • D It will not compile
Answer: Option C
Q35
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 a=0 b=6
  • B a=5=5
  • C a=5 b=6
  • D a=6 b=6
Answer: Option D
Q36
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 ?
  • A if (x ==0) return 0;
  • B if (x==0) return 1;
  • C if (x<=1)return 1;
  • D return 1;
Answer: Option C
Q37
if (x ? y : z) do something ( ); Refering to the sample above, which statement correctly identifies when y is evaluated ?
  • A y is evaluated only when x = = 1
  • B y is evaluated only when x >=1.
  • C y is evaluated only when x!=0
  • D y is evaluated only when x==0.
Answer: Option C
Q38
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 ?
  • A var 2 only
  • B var4 only
  • C var 2 and var 4 only
  • D var 2, var3, and var4 only
Answer: Option C
Q39
void func (int x) { if (x &gt; 0) func (--x); printf (&quot;%d, &quot;, x); } int main ( ) { func (5); return 0; } what will the above sample code produce when executed ?
  • A 0, 1, 2, 3, 4, 5
  • B 0, 0, 1, 2, 3, 4
  • C 4, 3, 2, 1, 0
  • D 5, 4, 3, 2, 1, 0
Answer: Option B
Q40
# include &lt;stdio.h&gt; void show ( ) { printf ( (&quot;Water\n&quot;); } /* main. c */ #include &lt;stdio.h&gt; static void show ( ) { printf (&quot;Drink\n&quot;); 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?
  • A it will print Water
  • B It will print Drink.
  • C It will print:
  • D Drink water
Answer: Option B
Questions and Answers for Competitive Exams Various Entrance Test