Questions and Answers, for CS 3251 – Programming in C. Part 6.
(For Part 5 of this series, pls see here: 16 marks Q & A on Loops (Unit 1). )


Pls see the above images. The same content is given in text form below.

Anna Univ Exam Prep: CS 3251: Programming in C: Previous Years Questions and Answers – Part 5.
In this post, Q&A related to Functions (Unit 3).

Question (Nov / Dec 2022) (16 marks)

(a) Classify function prototypes with suitable examples. (8 marks)

(b) Write a program to design scientific calculator using built-in functions. (8 marks)


Note: Part (a) of this question is answered in this post. Part (b) will be answered in a subsequent post.


Answer (a) Classification of function prototypes, with examples.
  • Function prototype is also known as function declaration.
  • It is written prior to the function call and the function definition.
  • It conveys the following information to the compiler:
    • Function name
    • Return type
    • Number of parameters and types of parameters

Based on return value and parameters/arguments, function prototypes are of 4 types:

  • Functions with no parameters and no return value.
  • Functions with one or more parameters, and no return value.
  • Functions with no parameters, and returning a value.
  • Functions with one or more parameters, and returning a value.

1. Function with no parameters, and no return value
  • Calling function does not pass any arguments.
  • Function does not return any value to the calling function.
#include <stdio.h>
void greet(void); // function prototype
int main()
{
greet(); // function call
return 0;
}
void greet(void) // function definition
{
printf("Have a nice day.\n");
}
output:
Have a nice day.

2. Function with one or more parameters, and no return value
  • Calling function passes one or more parameters (arguments).
  • Function does not return any value to the calling function.
#include <stdio.h>
void Add(int, int); // function prototype
int main()
{
Add(10, 20); // function call
return 0;
}
void Add(int m, int n) // function definition
{
printf("Sum of %d and %d is %d", m, n, m + n);
}
output:
Sum of 10 and 20 is 30

3. Function with no parameters, and returning a value
  • Calling function does not pass any parameters (arguments).
  • Function returns a value to the calling function.
#include <stdio.h>
int getCurrentYear(void); // function prototype
int main()
{
printf("Current year is %d", getCurrentYear()); // function call
return 0;
}
int getCurrentYear(void) // function definition
{
return 2026;
}
output:
Current year is 2026

4. Function with one or more parameters, and returning a value
  • Calling function passes one or more parameters (arguments).
  • Function returns a value to the calling function.
#include <stdio.h>
int Add(int, int); // function prototype
int main()
{
printf("Sum of %d and %d is %d", 10, 20, Add(10, 20)); // function call
return 0;
}
int Add(int m, int n) // function definition
{
return m + n;
}
output:
Sum of 10 and 20 is 30

To write a good answer for this question, do these things –

  • Explain briefly what a function prototype is.
  • Mention the 4 types of function prototypes.
  • Write simple code examples for each type.
    • When writing code, add comments to indicate which is function prototype, which is function call, and which is function definition.
  • write neatly and legibly.
Posted in

2 responses to “CS3251 Question Bank – Part 6. Functions (Unit 3). Anna Univ Previous Years Q & A. Programming in C.”

  1. […] CS3251 Question Bank – Part 6. Functions (Unit 3). Anna Univ Previous Years Q & A. Program… […]

    Like

  2. […] CS3251 Question Bank – Part 6. Functions (Unit 3). Anna Univ Previous Years Q & A. Program… […]

    Like

Leave a comment

Is this your new site? Log in to activate admin features and dismiss this message
Log In