0% found this document useful (0 votes)
83 views

Functions

The document contains questions and answers related to functions in the C programming language. Some key points covered include: - Functions allow code reuse and improve program structure. - Functions have a return type and may or may not return a value. - Recursive functions call themselves and are commonly used with loops. - The return keyword transfers control back to the calling function. - There is no limit on the number of functions or statements in a function. - Function arguments must match in type and order when calling and defining a function.

Uploaded by

Amulya Raj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Functions

The document contains questions and answers related to functions in the C programming language. Some key points covered include: - Functions allow code reuse and improve program structure. - Functions have a return type and may or may not return a value. - Recursive functions call themselves and are commonly used with loops. - The return keyword transfers control back to the calling function. - There is no limit on the number of functions or statements in a function. - Function arguments must match in type and order when calling and defining a function.

Uploaded by

Amulya Raj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Choose correct state ment about Functions in C


Language.

a) A Function is a group of c statements which can be reused


any number of times
b) Every Function has a return type
c) Every Function may no may not return a value
d) All the above

View Answer
2. Choose a correct statement about C Function?

void main() {
  printf("Hello");
}
a) "main" is the name of default must and should Function
b) main() is same as int main()
c) By default, return 0 is added as the last statement of a
function without specific return type
d) All the above

View Answer
Answer: D
No explanation is given for this question.

3. A function which calls itself is called a ___ function.

a) Self Function
b) Auto Function
c) Recursive Function
d) Static Function

View Answer
4. The keyword used to transfer control from a function
back to the calling function is

int **a;
a) switch
b) goto
c) go back
d) return

View Answer
Answer: D
The keyword return is used to transfer control from a function
back to the calling function.

5. How many times the program will print "Algbly"?

int main() {
  printf("Algbly");
  main();
  return 0;
}
a) Infinite times
b) 32767 times
c) 65535 times
d) Till stack overflows

View Answer
Answer: D
A call stack or function stack is used for several related
purposes, but the main reason for having one is to keep track
of the point to which each active subroutine should return
control when it finishes executing.
A stack overflow occurs when too much memory is used on
the call stack.
Here function main() is called repeatedly and its return
address is stored in the stack. After stack memory is full. It
shows stack overflow error.

6. Determine Output :

void show() {
  printf("PISTA ");
  show();
}

void main() {
  printf("CACHEW ");
  return 10;
}
a) PISTA CACHEW
b) CASHEW PISTA
c) PISTA CASHEW with compiler warning
d) Compiler error

View Answer
Answer: C
Here show() function should not return anything. So, return
10; is not recommended.

7. What are the types of functions in C Language?

a) Library Functions
b) User Defined Functions
c) Both Library and User Defined
d) None of the above

View Answer
8. Choose correct statements about C Language

Pass By Value.
a) Pass By Value copies the variable value in one more
memory location
b) Pass By Value does not use Pointers
c) Pass By Value protects your source or original variables from
changes in outside functions or called functions
d) All the above

View Answer
9. What is the limit for number of functions in a C
Program?

a) 16
b) 31
c) 32
d) No Limit

View Answer
10. Every C Program should contain which

Function?

a) printf()
b) show()
c) scanf()
d) main()

1. What is the minimum number of functions to be present


in a C Program?

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

View Answer
2. What is the maximum number of statements that can
present in a C function?

void main() {
  printf("Hello");
}
a) 64
b) 128
c) 256
d) None of the above

View Answer
Answer:
There is no limit on the number of statements that can present
in a C Function.

3. What characters are allowed in a C function name


identifier?

a) Alphabets, Numbers, %, $, _
b) Alphabets, Numbers, Underscore ( _ )
c) Alphabets, Numbers, dollar $
d) Alphabets, Numbers, %

View Answer
4. Arguments passed to a function in C language are called
___ arguments.

int **a;
a) Formal arguments
b) Actual Arguments
c) Definite Arguments
d) Ideal Arguments

View Answer
Answer: B
No explanation is given for this question.

5. Arguments received by a function in C language are


called ___ arguments.

a) Definite arguments
b) Formal arguments
c) Actual arguments
d) Ideal arguments

View Answer
Answer: B
No explanation is given for this question.

6. Choose a corrects statement about C language function


arguments.

a) Number of arguments should be same when sending and


receiving
b) Type of each argument should match exactly
c) Order of each argument should be same
d) All the above

View Answer
Answer: 
No explanation is given for this question.

7. Choose a non Library C function below.

a) printf()
b) scanf()
c) fprintf()
d) printf4()

View Answer
8. What is the default return value of a C function if not
specified explicitly?

a) -1
b) 0
c) 1
d) None of the above

View Answer
Answer: 
By default, a return 0; is added at the end of any function if not
explicitly specified.

9. It is necessary to declare the type of a function in the


calling program if the function

a) Is not defined in the same file


b) Returns a non-integer value
c) Both A and B
d) None of the above

View Answer
Answer: 
No explanation for this question.

10. Uses of function

a) Helps to avoid repeating a set of statements many times


b) Enhances the logical clarity of the program
c) Helps to avoid repeated programming across programs
d) Makes the debugging task easier
e) All of the above

1.It is necessary to declare the type of a function in the


calling program if the function
a) Return an integer
b) Returns a non-integer value
c) is not defined in the same file
d) None of these

View Answer

3. The function that actually created from a call to a


template function is called

a) Generated
b) Inherited
c) Spawned
d) Declassified

View Answer
4. The function fprintf is used in a program.

a) When too many printf calls have been alrady used in the
program
b) In place of printf, since printf uses more memory
c) When output i to be printed on to a file
d) All of above

View Answer
Answer: 
No explanatin is given for this question.

5. What is the output of C program with pointers.

int main() {
  int a = 20;
  //a memory location = 1234
  printf("%d %d %d %d", a, &a, *(&a));
  return 0;
}
a) 20 20 20
b) 20 1234 1234
c) 20 1234 20
d) 20 20 20

View Answer
6. What is the output of C program with functions?

int main() {
  int a = 20;
  printf("CINEMA ");
  return 1;
  printf("DINOSAUR ");
  return 1;
}
a) CINEMA DINOSAUR
b) CINEMA
c) DINOSAUR
d) Compiler error

View Answer
Answer: 
There are two return statements in main() function. Only first
return is executed. All the statements or lines of code below
first return is not reachable and hence not executed.

7. What is the output of C program with recursive


function?

int sum(int x) {
  int k = 1
  if(x <= 1)
    return 1;
  k = x + sum(x - 1);
    return k;
}
a) 10
b) 11
c) 12
d) 15

View Answer
8. A recursive function can be replaced with __ in C
language.

a) for loop
b) while loop
c) do while loop
d) All the above

View Answer
9. A recursive function is faster than __ loop.

a) for
b) while
c) do while
d) None of the above

View Answer
10. What is the C keyword that must be used to achieve
expected result using Recursion?

a) printf
b) scanf
c) void
d) return
1. What is the output of this C code?

int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}
 A. Compile time error as foo is local to main
 B. 1   2
 C. 2   1
 D. Compile time error due to declaration of functions
inside main

 View Answer

 Workspace

 Report

 Discuss
Answer & Explanation
2. What is the output of this C code?
int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}
 A. 2   2
 B. 2
 C. Compile time error
 D. Depends on the compiler

 View Answer

 Workspace

 Report

 Discuss

3. What is the output of this C code?

void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}
 A. Compile time error
 B. 2
 C. Depends on the compiler
 D. Depends on the standard

 View Answer

 Workspace

 Report

 Discuss

4. What is the output of this C code?

void foo();
int main()
{
void foo(int);
foo(1);
return 0;
}
void foo(int i)
{
printf("2 ");
}
 A. 2
 B. Compile time error
 C. Depends on the compiler
 D. Depends on the standard

 View Answer

 Workspace

 Report

 Discuss

5. What is the output of this C code?

void foo();
int main()
{
void foo(int);
foo();
return 0;
}
void foo()
{
printf("2 ");
}
 A. 2
 B. Compile time error
 C. Depends on the compiler

You might also like