Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Programming and Data Structures  >  Test: Functions in C - Computer Science Engineering (CSE) MCQ

Test: Functions in C - Computer Science Engineering (CSE) MCQ


Test Description

10 Questions MCQ Test Programming and Data Structures - Test: Functions in C

Test: Functions in C for Computer Science Engineering (CSE) 2024 is part of Programming and Data Structures preparation. The Test: Functions in C questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Functions in C MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Functions in C below.
Solutions of Test: Functions in C questions in English are available as part of our Programming and Data Structures for Computer Science Engineering (CSE) & Test: Functions in C solutions in Hindi for Programming and Data Structures course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Functions in C | 10 questions in 30 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study Programming and Data Structures for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
Test: Functions in C - Question 1

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);
}

Detailed Solution for Test: Functions in C - Question 1

In C, functions are global by default. Unlike global functions, access to static functions is restricted to the file where they are declared. We can have file level encapsulation using static variables/functions in C because when we make a global variable static, access to the variable becomes limited to the file in which it is declared.

Test: Functions in C - Question 2

Predict the output?

#include <stdio.h>
int main()
{
    void demo();
    void (*fun)();
    fun = demo;
    (*fun)();
    fun();
    return 0;
}
void demo()
{
    printf("EduRevQuiz ");
}

Detailed Solution for Test: Functions in C - Question 2

This is a simple program with function pointers. fun is assigned to point to demo. So the two statements "(*fun)();" and "fun();" mean the same thing.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Functions in C - Question 3

What is the output ?

#include <stdio.h>
int main()
{
    int (*ptr)(int ) = fun;
    (*ptr)(3);
    return 0;
}
int fun(int n)
{
  for(;n > 0; n--)
    printf("EduRevQuiz ");
  return 0;
}

Detailed Solution for Test: Functions in C - Question 3

The only problem with program is fun is not declared/defined before it is assigned to ptr. The following program works fine and prints "EduRevQuiz EduRevQuiz EduRevQuiz "

int fun(int n);

int main()
{
    // ptr is a pointer to function fun()
    int (*ptr)(int ) = fun;

    // fun() called using pointer 
    (*ptr)(3);
    return 0;
}

int fun(int n)
{
  for(;n > 0; n--)
    printf("EduRevQuiz ");
}

Test: Functions in C - Question 4

Which of the following is true about return type of functions in C?

Detailed Solution for Test: Functions in C - Question 4

In C, functions can return any type except arrays and functions. We can get around this limitation by returning pointer to array or pointer to function.

Test: Functions in C - Question 5

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

Detailed Solution for Test: Functions in C - Question 5

Name of the function is actually a pointer variable to the function and prints the address of the function. Symbol table is implemented like this.

struct
{
   char *name;
   int (*funcptr)();
}
symtab[] = {
   "func", func,
   "anotherfunc", anotherfunc,
};

Test: Functions in C - Question 6

Output of following program?

#include <stdio.h>
int main()
{
    int i = 5;
    printf("%d %d %d", i++, i++, i++);
    return 0;
}

Detailed Solution for Test: Functions in C - Question 6

When parameters are passed to a function, the value of every parameter is evaluated before being passed to the function. What is the order of evaluation of parameters - left-to-right or right-to-left? If evaluation order is left-to-right, then output should be 5 6 7 and if the evaluation order is right-to-left, then output should be 7 6 5. Unfortunately, there is no fixed order defined by C standard. A compiler may choose to evaluate either from left-to-right. So the output is compiler dependent.

Test: Functions in C - Question 7

In C, what is the meaning of following function prototype with empty parameter list

void fun()
{
   /* .... */
}

Detailed Solution for Test: Functions in C - Question 7

Empty list in C mean that the parameter list is not specified and function can be called with any parameters. In C, to declare a function that can only be called without any parameter, we should use "void fun(void)" As a side note, in C++, empty list means function can only be called without any parameter. In C++, both void fun() and void fun(void) are same.

Test: Functions in C - Question 8

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);
}

Detailed Solution for Test: Functions in C - Question 8

extern keyword is used for global variables. Functions are global anyways, so adding extern doesn't add anything.

Test: Functions in C - Question 9

Output of following program?

#include<stdio.h>
void dynamic(int s, ...)
{
    printf("%d ", s);
}
int main()
{
    dynamic(2, 4, 6, 8);
    dynamic(3, 6, 9);
    return 0;
}

Detailed Solution for Test: Functions in C - Question 9

In c three continuous dots is known as ellipsis which is variable number of arguments of function. The values to parameters are assigned one by one. Now the question is how to access other arguments. See this for details.

Test: Functions in C - Question 10

In C, parameters are always 

Detailed Solution for Test: Functions in C - Question 10

Answer:(A) Explanation:In C, function parameters are always passed by value. Pass-by-reference is simulated in C by explicitly passing pointer values.

119 docs|30 tests
Information about Test: Functions in C Page
In this test you can find the Exam questions for Test: Functions in C solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Functions in C, EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)