Skip to the content
onlineexamguide
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
    • CS & IT Engg.
      • C programming Tests
      • C++ programming Tests
      • Java Programming Tests
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
    • About us
    • Privacy Policy
  • Cart
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
    • CS & IT Engg.
      • C programming Tests
      • C++ programming Tests
      • Java Programming Tests
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
    • About us
    • Privacy Policy
  • Cart
  • User Login

C MCQ Questions and Answers on Functions and Pointers

Functions in C

Learn C MCQ Questions and Answers on Functions in C and Pointers in c on Basics to attend job placement exams, interview questions, college viva and Lab Tests

C language is built up of a number of functions. A function is a group of statements or block of statements that servers a specific purpose.

Type of Functions in C

There are two types of functions in a C language.

  1. Library Functions
  2. User Defined Functions

1. Library Functions

As the name suggests, Library functions are predefined functions written for specific purposes like printing, scanning input and more. To use library functions, you have to include the header files with the file name extension DOT-H (.h) in your C program using a Preprocessor Directive.

2. User Defined Functions

User defined functions are the functions defined or written by you in your C program. You can define any number of functions in a C program.

Syntax of a Function

RETURN-TYPE FUNCTION_NAME(PARAMERTER1, PARAMETER2,..)
{
  STATEMENTS; // FUNCTION LOGIC
  return SOME_VALUE;
}

Notes about Writing and Working of a Function in C

  1. A function name should follow the same guidelines of choosing a Variable name
  2. A function name can not start with a number. It can start with an Underscore ( _ ) symbol.
  3. A function name can contain Alphabets, numbers and Special character like Underscore.
  4. Same function name should be repeated again in the same C program.
  5. Popular ‘return’ keyword is used most with functions.
  6. Default Return type of a function is a Garbage Integer value if not specified explicitly.
  7. A function can return only one value at a time.
  8. You can put any number of RETURN statements in a c program.
  9. You need not write a RETURN statement. It is not suggested.
  10. main() is also a function which is invoked or called or started automatically on execution.
  11. Any executable C program must contain main() function.
  12. Other programming languages call functions as methods.
  13. Arguments are nothing but Parameters a function accepts.
  14. and Arguments received in a function are called FORMAL ARGUMENTS.
  15. Arguments passed to a function are called ACTUAL ARGUMENTS.
  16. Variables defined in a C program are called Local Variables. Local variables die after execution of the function.
  17. Static Storage Class Variables in a function Retain their value among multiple calls.
  18. Functions accept all types of data i.e int, long, float, double, char and pointers.
  19. Arguments are values a function accepts from a calling function. Accepting arguments is not mandatory.
  20. If you call a function SOMEFUNCTION() from main() function, then the main function is called CALLING FUNCTION and SOMEFUNCTION() is called CALLED FUNCTION.
  21. There is no limit on the number of different functions being defined in a C program.
  22. A function may be called any number of times.
  23. Nesting of functions or defining a function inside another function is not allowed.
  24. Passing or arguments are processed from Right to Left in C Language.
  25. A function can call itself. This process is called Recursion.

Functions in C 

Example 1: Area of Rectangle Function

int area(int,int);
int main()
{
  int x=5, y=6;
  int z = area(x,y);
  int p = area(2,6);
  printf("%d, %d", z, p);

  return 9;
}
int area(int a, int b)
{
  return (a*b);
}
//output
//30, 12

In the above program, we passes arguments x and y to the function area(). Function area() returned calculated area which is assigned to the variable Z. You can directly call a function with constants without using any variables like area(2,6).

Functions in C 

Example 2: Using Library functions

#include<math.h>
int main()
{
  float x=1;
  float a = sin(x);
  printf("%f", a);

  return 9;
}

We have to INCLUDE the Header file of the Library we want to use. Different functions are included in different libraries. As we are dealing with Trigonometric functions, we have included MATH.H file.

Recursion or Recursive Functions

A function which calls itself is called a Recursive Function and the process is called Recursion.

  1. To create a recursive function, exit condition must be specified without which it becomes never ending recursion and the program crashes.
  2. Recursion is slow compared to normal WHILE, FOR and DO WHILE loops.
  3. Recursion logic by one developer is difficult to understand for other developers.
  4. Usually, IF or ELSE conditions are used to END recursion.

Example 1:

int main()
{
  int a = 4335;
  int no_of_digits = func(a);
  printf("NO=%d", no_of_digits);

  return 9;
}
int func(int p)
{
  int k;
  if(p<10)
    return 1;
  else
    k = 1 + func(p/10);

  return k;
}
//output
//NO=4
//Analysis
//Step1: 1 + func(433)
//Step2: 1 + (1 + func(43))
//Step3: 1 + (1 + (1 + func(4)))
//Step4: 1 + (1 + (1 + 1) )

Above recursive function takes the input number a P. Using recursion, it counts number of digits present in the given number.

Pointers in Functions

Pointers are used along with functions to pass variables and address of variables from one function to the other.

There are two ways of calling a function with arguments.

  1. Call By Value
  2. Call By Reference

1. Call By Value / Pass by Reference

If you pass only variables or constants to a function, it is called Call By Value. Because you do not use any Pointers or Addresses. Advantage of Call By Value is that the original values of passing variables do not change when you make changes in the called function.

Example

void show(int);
int main()
{
  int a=10;
  show(a); //CALL BY VALUE
  printf("%d", a);
}
void show(int x)
{
  x = x + 1; //Here it is not a.
  printf("%d,", x);
  return;
}
//output:
//11,10
//Value of a is not changed.

2. Call By Reference / Pass by Reference

Call By Reference passes addresses of variables to another function. So whatever changes you make to the variables in the CALLED function reflect in the CALLING function. It has side effects.

Two operators namely ADDRESS OF (&) and VALUE AT ADDRESS (*) operators are used to pass addresses by call by reference.

C MCQ Questions and Answers on Functions and Pointers 

Example

void show(int*);
int main()
{
  int a=10;
  show(&a); //CALL BY Reference
  printf("%d", a);
}
void show(int *x)
{
  *x = *x + 1; //Here it is A only.
  printf("%d,", *x);
  return;
}
//output:
//11,11
//Value of a is CHANGED.

&a is the address of the Variable ‘a’.  *x is the value at the address passed. So you are changing the original copy of data in memory location passed. This is called CALL BY REFERENCE.

C MCQ Questions and Answers on Functions and Pointers online test

[WpProQuiz 31]

Write a comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Atal Bihari Vajpayee | श्री अटल बिहारी वाजपेयी जीवन परिचय
  • सम्राट अशोक का जीवन परिचय (Emperor Ashoka)
  • Prithviraj Chauhan
  • बाल गंगाधर तिलक
  • स्वामी दयानंद सरस्वती
  • UPPSC Mines Inspector Recruitment 2022 Notification Out
  • AIIMS Delhi JR Vacancy 2022 [194 Post] Notification and Apply Online
  • भीमराव अम्बेडकर
  • डॉक्टर राजेंद्र प्रसाद का जीवन परिचय
  • श्रीनिवास रामानुजन का जीवन परिचय
  • Amnesty International day
  • World Economic Forum
  • UPSSSC VDO Syllabus and Exam Pattern 2022
  • RBI Officer Grade B Recruitment 2022
  • UKMSSB Assistant Professor Recruitment 2022 Apply Now 339 Post

About us

Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Select Language

Follow us

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Copyright © 2022 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.