Pages

Wednesday, 28 August 2019

CBSE Class 11 - Computer Science (C++) - User Defined Function - Q & A (#class11ComputerScience)(#cbsenotes)(#eduvictors)

Class 11 - Computer Science (C++)
User Defined Functions 

Q & A
CBSE Class 11 - Computer Science (C++) - User Defined Function - Q & A (#class11ComputerScience)(#cbsenotes)(#eduvictors)


SHORT ANSWER TYPE QUESTIONS

Q1(MCQ): A function’s single most important role is to
(a) give a name to a block of code
(b) reduce program size
(c) accept argument and provide a return value
(d) help organize a program well

Answer: (d) help organize a program well


Q2: Define a function. What is the name of one-statement description of a function?

Answer: A function is a subprogram that acts on data and often returns a value. The name of one-statement description of a function is procedure or prototype.

OR 

A function has a name that both identifies it and is used to call it for execution in a program


Q3: Function prototype is alternatively called. What is the statement specifically called that invokes a function?

Answer: A function prototype is alternatively called function declaration. The statement that invokes a function is specifically called function call.



Q4. What is a function declaration? How is a function declaration different from a function definition?

Answer: A function declaration tells the program about the type of the value returned by the function and the number and type of arguments.

A function declaration has no body and no code. e.g.

double power(double x, int n)
It consists of three parts:
- type of return value i.e. in above example it is double value.
- name the function i.e. power in above said example
- Parameters of the function enclosed between parentheses i.e. x and n in above example.

In other words, a (prototype) declaration introduces a function name to the program. On the other hand, a definition tells the Program, what is the function doing and how is it doing so.


Q5: What are actual and formal parameters of a function?

Answer: The parameter that appear in a function call statement i.e., which are passed are actual parameters. The parameters that appear in function definition i.e. passed values are called actual parameters.


Q6: Where ¡s a function’s return type specified? What ¡s the return type of a function that does not return a value?
How many values can be returned from a function?

Answer: A function’s return type is specified first in the function prototype.
double power(double x, int n)
In the above example, the function power returns double value.
The return type of a function that does not return a value is void. Only one value can be returned from a function.
e.g.
void my_function(void);
void my_function();


Q7: What are global and local prototypes?

Answer: If the function’s prototype appears outside all other functions in the program file, then it is called global prototype.
If the function’s prototype appears within another functions in the program file, then it is called local prototype.


Q8: When can a function prototype be omitted?

Answer: When the function definition appears before its calling function.


Q9:  Construct function prototype for descriptions given below:
(i) myfunc() take no argument and has no return value.
(ii) mains() takes a float argument and returns an int.
(iii) newfunc() takes two double arguments and returns a double.
(iv) sum() takes an int array and an int value and returns a long result.


Answer:
(i)   void myfunc();
(ii)  int mains(float);
(iii) double newfunc (double x, double y);
(iv)  long sum(int arr[], int j);


Q10: How many ways arguments are passed to a function?

Answer:
(i) Pass by Value
(ii) Pass by reference
(iii) Pass by address (pointers)


Q11: What is the difference between a parameter and an argument?

Answer: Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function.

Often the two terms are used interchangeably.



See also:
CH1 - Computer Overview
CH6 - Getting Started With C++
CH11 - Flow Of Control

SA1-Computer Science - Sample Question Paper
Computer Science (C++) Half Year Exam - Question Paper (2018-19)
Computer Science (C++) Annual Question Paper (2018-19)

No comments:

Post a Comment

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.