SlideShare une entreprise Scribd logo
1  sur  6
OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 1
DHANALAKSHMI COLLEGE OF ENGINEERING
Tambaram, Chennai
Department of Computer Science and Engineering
OCS752 INTRODUCTION TO C PROGRAMMING
Year / Sem : IV / VII
2 Marks Q & A
OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 2
UNIT IV
FUNCTIONS
Introduction to Functions – Types: User-defined and built-in functions – Function prototype – Function
definition – Function call – Parameter passing: Pass by value – Pass by reference – Built-in functions
(string functions) – Recursive functions – Exercise programs: Calculate the total amount of power
consumed by ‘n’ devices (passing an array to a function) – Menu-driven program to count the numbers
which are divisible by 3, 5 and by both (passing an array to a function) – Replace the punctuations
from a given sentence by the space character (passing an array to a function)
PART – A
1. What is a function? (N/D – 14, N/D – 16, N/D – 19)
A function is a group of statements that together perform a task. The general form of a function
definition in C language:
return_type function_name( parameter list )
{
body of the function
}
2. Specify the advantages of function. (A/M – 16, A/M – 19)
Advantages of function
1) The program will be easier to understand, maintain and debug.
2) Reusable codes that can be used in other programs
3) A large program can be divided into smaller modules. Hence, a large project can be divided
among many programmers.
3. What does a function header and function body consist of?
A function definition consists of
1) Function header
2) Function body
The Function header consists of
1) Return Type
2) Function Name
3) Parameters
The Function body consists of
Declarations and statements necessary for performing the required task.
4. What is a recursive function?
A Function calls itself again and again, then that function is called Recursive function. This
technique is known as recursion.
OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 3
Example:
void recursion()
{ recursion(); /* function calls itself */
}
int main()
{
recursion();
}
5. Differentiate pass by value from pass by reference. (A/M – 14, N/D – 17)
S. No. Pass by value Pass by reference
1 A copy of actual arguments is passed to
formal arguments of the called function.
The location (address) of actual arguments is
passed to formal arguments of the called
function.
2 Actual arguments will remain safe and
they cannot be modified accidentally.
Alteration to actual arguments is possible
within the called function.
6. List the advantages of recursion. (A/M – 18)
Advantages of recursion
1) Reduce unnecessary calling of function.
2) Through recursion one can solve problems in easy way, while its iterative solution is very big
and complex.
7. What are actual parameters and formal parameters? (A/M – 15)
Functions can take two kinds of parameters.
1) Actual parameter
2) Formal parameter
Actual parameters are parameters as they appear in function calls. Formal parameters are parameters
as they appear in function declarations.
8. Write a program to print the first 50 prime numbers recursively. (N/D – 15)
Program to print the first 50 prime numbers recursively
#include<stdio.h>
void main ( )
{
intn,i=3, j, c;
scanf("%d",&n);
for(i=3;i<=n;i++)
{
OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 4
c=0;
{
for (j=1;j<=i;j++)
if(i%j==0)
c++;
}
if(c==2)
{
printf("%d",i);
}}}
Output:
50
357111317192329313739414347
9. What are the components of a function? (A/M – 17)
Components of a function
1) Function declaration
2) Function definition
3) Function call
10. What are the steps in writing a function in a program? (N/D – 19)
Steps in writing a function in a program
1) Function Declaration (Prototype declaration): Every user-defined function has to be declared
before the main ().
2) Function Callings: The user-defined functions can be called inside any function like main(),
user-defined function, etc.
3) Function Definition: Once a function is declared and defined, it can be called any number of
times, from any function.
11. Is it better to use a macro or a function? (N/D – 19)
Macros are more efficient than function because their corresponding code is inserted directly at the
point where the macro is called. Macros are generally small and cannot handle large, complex
coding constructs. Functions are used for large, complex coding constructs.
12. Is main() a library function in C?
The function main() is not a predefined or built in function. It is a user defined function with a
predefined function prototype (also called function signature). It is neither user defined nor a built in
library function.
OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 5
13. Distinguish between exit ( ) and return in C.
S. No. exit() return
1) exit() is a system call (not a language
statement) that terminates the current
process.
return is an instruction of the language
that returns from a function call.
2) #include <stdio.h>
void f()
{
printf("Executing fn");
exit(0);
}
int main()
{
f();
printf("Back from fn");
}
#include <stdio.h>
void f()
{
printf("Executing fn");
return;
}
int main()
{
f();
printf("Back from fn");
}
14. How to generate random numbers in C?
rand() function is used in C to generate random numbers. If we generate a sequence of random
number with rand() function, it will create the same sequence again and again every time program
runs.
15. Classify the functions based on arguments and return values.
Depending on the arguments and return values, functions are classified into four types.
1) Function without arguments and return values.
2) Function with arguments but without return values.
3) Function without arguments but with return values.
4) Function with arguments and return values.
16. List the types of functions in C programming.
Depending on whether a function is defined by the user or already included in C compilers,
there are two types of functions in C programming
1) Standard library functions
2) User defined functions
17. List the advantages of functions. (A/M – 14)
Advantages of functions
OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 6
1) Functions are self-contained block or sub program of one or more statements that performs a
specific task.
2) It increases the modularity, reusability of a program.
18. List the advantages of user-defined function.
Advantages of user defined functions
1) The program will be easier to understand, maintain and debug.
2) Reusable codes that can be used in other programs
3) A large program can be divided into smaller modules. A large project can be divided among
many programmers.
19. What are standard library functions?
The standard library functions are built-in functions in C programming to handle tasks such as
mathematical computations, I/O processing, string handling. These functions are defined in the
header file.
20. What is function prototyping? Why it is necessary? (A/M – 11)
Many built in functions can be used in C programs. The prototype of these functions is given in the
respective header files. With the help of a function prototype, the compiler can automatically
perform type checking on the definition of the function, which saves the time to delay the program.

Contenu connexe

Tendances

Tendances (20)

Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Ram and-rom-chips
Ram and-rom-chipsRam and-rom-chips
Ram and-rom-chips
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Computer instruction
Computer instructionComputer instruction
Computer instruction
 
C Programming
C ProgrammingC Programming
C Programming
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Structure in C
Structure in CStructure in C
Structure in C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
C Pointers
C PointersC Pointers
C Pointers
 

Similaire à Ocs752 unit 4

U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in CSyed Mustafa
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2yndaravind
 
Functions part1
Functions part1Functions part1
Functions part1yndaravind
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Functional Paradigm.pptx
Functional Paradigm.pptxFunctional Paradigm.pptx
Functional Paradigm.pptxFurretMaster
 
functions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxfunctions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxMehakBhatia38
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
 
Lecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptxLecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptxravi2692kumar
 

Similaire à Ocs752 unit 4 (20)

U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
C structure
C structureC structure
C structure
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
Functions part1
Functions part1Functions part1
Functions part1
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
3 Function & Storage Class.pptx
3 Function & Storage Class.pptx3 Function & Storage Class.pptx
3 Function & Storage Class.pptx
 
Functional Paradigm.pptx
Functional Paradigm.pptxFunctional Paradigm.pptx
Functional Paradigm.pptx
 
functions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxfunctions in c language_functions in c language.pptx
functions in c language_functions in c language.pptx
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Function
FunctionFunction
Function
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
 
Lecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptxLecture 3.2.4 C pointer to Structure.pptx
Lecture 3.2.4 C pointer to Structure.pptx
 

Dernier

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 

Dernier (20)

Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 

Ocs752 unit 4

  • 1. OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 1 DHANALAKSHMI COLLEGE OF ENGINEERING Tambaram, Chennai Department of Computer Science and Engineering OCS752 INTRODUCTION TO C PROGRAMMING Year / Sem : IV / VII 2 Marks Q & A
  • 2. OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 2 UNIT IV FUNCTIONS Introduction to Functions – Types: User-defined and built-in functions – Function prototype – Function definition – Function call – Parameter passing: Pass by value – Pass by reference – Built-in functions (string functions) – Recursive functions – Exercise programs: Calculate the total amount of power consumed by ‘n’ devices (passing an array to a function) – Menu-driven program to count the numbers which are divisible by 3, 5 and by both (passing an array to a function) – Replace the punctuations from a given sentence by the space character (passing an array to a function) PART – A 1. What is a function? (N/D – 14, N/D – 16, N/D – 19) A function is a group of statements that together perform a task. The general form of a function definition in C language: return_type function_name( parameter list ) { body of the function } 2. Specify the advantages of function. (A/M – 16, A/M – 19) Advantages of function 1) The program will be easier to understand, maintain and debug. 2) Reusable codes that can be used in other programs 3) A large program can be divided into smaller modules. Hence, a large project can be divided among many programmers. 3. What does a function header and function body consist of? A function definition consists of 1) Function header 2) Function body The Function header consists of 1) Return Type 2) Function Name 3) Parameters The Function body consists of Declarations and statements necessary for performing the required task. 4. What is a recursive function? A Function calls itself again and again, then that function is called Recursive function. This technique is known as recursion.
  • 3. OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 3 Example: void recursion() { recursion(); /* function calls itself */ } int main() { recursion(); } 5. Differentiate pass by value from pass by reference. (A/M – 14, N/D – 17) S. No. Pass by value Pass by reference 1 A copy of actual arguments is passed to formal arguments of the called function. The location (address) of actual arguments is passed to formal arguments of the called function. 2 Actual arguments will remain safe and they cannot be modified accidentally. Alteration to actual arguments is possible within the called function. 6. List the advantages of recursion. (A/M – 18) Advantages of recursion 1) Reduce unnecessary calling of function. 2) Through recursion one can solve problems in easy way, while its iterative solution is very big and complex. 7. What are actual parameters and formal parameters? (A/M – 15) Functions can take two kinds of parameters. 1) Actual parameter 2) Formal parameter Actual parameters are parameters as they appear in function calls. Formal parameters are parameters as they appear in function declarations. 8. Write a program to print the first 50 prime numbers recursively. (N/D – 15) Program to print the first 50 prime numbers recursively #include<stdio.h> void main ( ) { intn,i=3, j, c; scanf("%d",&n); for(i=3;i<=n;i++) {
  • 4. OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 4 c=0; { for (j=1;j<=i;j++) if(i%j==0) c++; } if(c==2) { printf("%d",i); }}} Output: 50 357111317192329313739414347 9. What are the components of a function? (A/M – 17) Components of a function 1) Function declaration 2) Function definition 3) Function call 10. What are the steps in writing a function in a program? (N/D – 19) Steps in writing a function in a program 1) Function Declaration (Prototype declaration): Every user-defined function has to be declared before the main (). 2) Function Callings: The user-defined functions can be called inside any function like main(), user-defined function, etc. 3) Function Definition: Once a function is declared and defined, it can be called any number of times, from any function. 11. Is it better to use a macro or a function? (N/D – 19) Macros are more efficient than function because their corresponding code is inserted directly at the point where the macro is called. Macros are generally small and cannot handle large, complex coding constructs. Functions are used for large, complex coding constructs. 12. Is main() a library function in C? The function main() is not a predefined or built in function. It is a user defined function with a predefined function prototype (also called function signature). It is neither user defined nor a built in library function.
  • 5. OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 5 13. Distinguish between exit ( ) and return in C. S. No. exit() return 1) exit() is a system call (not a language statement) that terminates the current process. return is an instruction of the language that returns from a function call. 2) #include <stdio.h> void f() { printf("Executing fn"); exit(0); } int main() { f(); printf("Back from fn"); } #include <stdio.h> void f() { printf("Executing fn"); return; } int main() { f(); printf("Back from fn"); } 14. How to generate random numbers in C? rand() function is used in C to generate random numbers. If we generate a sequence of random number with rand() function, it will create the same sequence again and again every time program runs. 15. Classify the functions based on arguments and return values. Depending on the arguments and return values, functions are classified into four types. 1) Function without arguments and return values. 2) Function with arguments but without return values. 3) Function without arguments but with return values. 4) Function with arguments and return values. 16. List the types of functions in C programming. Depending on whether a function is defined by the user or already included in C compilers, there are two types of functions in C programming 1) Standard library functions 2) User defined functions 17. List the advantages of functions. (A/M – 14) Advantages of functions
  • 6. OCS752 − INTRODUCTION TO C PROGRAMMING VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 6 1) Functions are self-contained block or sub program of one or more statements that performs a specific task. 2) It increases the modularity, reusability of a program. 18. List the advantages of user-defined function. Advantages of user defined functions 1) The program will be easier to understand, maintain and debug. 2) Reusable codes that can be used in other programs 3) A large program can be divided into smaller modules. A large project can be divided among many programmers. 19. What are standard library functions? The standard library functions are built-in functions in C programming to handle tasks such as mathematical computations, I/O processing, string handling. These functions are defined in the header file. 20. What is function prototyping? Why it is necessary? (A/M – 11) Many built in functions can be used in C programs. The prototype of these functions is given in the respective header files. With the help of a function prototype, the compiler can automatically perform type checking on the definition of the function, which saves the time to delay the program.