• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Functions

Question 1

Output of following program? C
#include <stdio.h>
int main()
{
    int i = 5;
    printf(\"%d %d %d\", i++, i++, i++);
    return 0;
}
  • 7 6 5
  • 5 6 7
  • 7 7 7
  • Compiler Dependent

Question 2

What is the output of this program?

C
#include <stdio.h>
int main()
{
  printf("%d", main);  
  return 0;
}
  • Address of main function

  • Compiler Error

  • Runtime Error

  • Some random value

Question 3

Output? C
#include <stdio.h>

int main()
{
    int (*ptr)(int ) = fun;
    (*ptr)(3);
    return 0;
}

int fun(int n)
{
  for(;n > 0; n--)
    printf(\"GeeksQuiz \");
  return 0;
}
  • GeeksQuiz GeeksQuiz GeeksQuiz
  • GeeksQuiz GeeksQuiz
  • Compiler Error
  • Runtime Error

Question 4

Output of following program? 

C
#include<stdio.h>

void dynamic(int s, ...)
{
    printf("%d", s);
}

int main()
{
    dynamic(2, 4, 6, 8);
    dynamic(3, 6, 9);
    return 0;
}
  • 2 3

  • Compiler Error

  • 4 3

  • 3 2

Question 5

Predict the output? C
#include <stdio.h>
int main()
{
    void demo();
    void (*fun)();
    fun = demo;
    (*fun)();
    fun();
    return 0;
}

void demo()
{
    printf(\"GeeksQuiz \");
}
  • GeeksQuiz
  • GeeksQuiz GeeksQuiz
  • Compiler Error
  • Blank Screen

Question 6

What is the meaning of using extern before function declaration? For example following function sum is made extern
extern int sum(int x, int y, int z)
{
    return (x + y + z);
}
  • Function is made globally available
  • extern means nothing, sum() is same without extern keyword.
  • Function need not to be declared before its use
  • Function is made local to the file.

Question 7

What is the meaning of using static before function declaration? For example following function sum is made static
static int sum(int x, int y, int z)
{
    return (x + y + z);
}
  • Static means nothing, sum() is same without static keyword.
  • Function need not to be declared before its use
  • Access to static functions is restricted to the file where they are declared
  • Static functions are made inline

Question 8

In C, what is the meaning of following function prototype with empty parameter list C
void fun()
{
   /* .... */
}
  • Function can only be called without any parameter
  • Function can be called with any number of parameters of any types
  • Function can be called with any number of integer parameters.
  • Function can be called with one integer parameter.

Question 9

C
#include <stdio.h>
#include <stdarg.h>
int fun(int n, ...)
{
    int i, j = 1, val = 0;
    va_list p;
    va_start(p, n);
    for (; j < n; ++j)
    {
        i = va_arg(p, int);
        val += i;
    }
    va_end(p);
    return val;
}
int main()
{
    printf(\"%d\\n\", fun(4, 1, 2, 3));
    return 0;
}
  • 3
  • 5
  • 6
  • 10

Question 10

Consider the following C-program: C
void foo(int n, int sum)
{
  int k = 0, j = 0;
  if (n == 0) return;
    k = n % 10; 
  j = n / 10;
  sum = sum + k;
  foo (j, sum);
  printf (\"%d,\", k);
}
 
int main ()
{
  int a = 2048, sum = 0;
  foo (a, sum);
  printf (\"%d\\n\", sum);
   
  getchar();
}
What does the above program print?
  • 8, 4, 0, 2, 14
  • 8, 4, 0, 2, 0
  • 2, 0, 4, 8, 14
  • 2, 0, 4, 8, 0

There are 41 questions to complete.

Last Updated :
Take a part in the ongoing discussion