C++ Questions

Q:

What is function prototyping? What are its advantages?

Answer

Function prototyping is a function declaration statement that tells the compiler about the return type of the function and the number as well as type of arguments required by the function at the time of calling it.


Syntax:


return_type function_name( type1 arg1, type 2 arg2, ... );


 


Advantages of function prototype :


- It helps the compiler in determining whether a function is called correctly or not. Each time when a function is called, its calling statement is compared with its prototype. In case of any mismatch, compiler reports an error.


- A function must be defined before calling it. But prototyping allows a function to be called before defining it.

Report Error

View answer Workspace Report Error Discuss

Subject: C++ - Technology

34 21324
Q:

What is the difference between stack and array?

Answer

Stack:


 - Stack is a ordered collection of items


 - Stack is a dynamic object whose size is constantly changing as items are pushed and popped .


 - Stack may contain different data types


Array:


- Array is an ordered collection of items


- Array is a static object i.e. no of item is fixed and is assigned by the declaration of the array


- It contains same data types.

Report Error

View answer Workspace Report Error Discuss

Subject: C++ - Technology Exam Prep: GATE

24 15014
Q:

Which of the following gives the memory address of the first element in array?

A) array[0]; B) array[1];
C) array(2); D) array;
 
Answer & Explanation Answer: D) array;

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

20 20798
Q:

What is the default return type of a function ?

A) int B) void
C) float D) char
 
Answer & Explanation Answer: B) void

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

19 16402
Q:

Which of the following is not the member of class?

A) Virtual function B) Static function
C) Friend function D) Const function
 
Answer & Explanation Answer: C) Friend function

Explanation:
Report Error

View Answer Report Error Discuss

19 7954
Q:

Which is more effective while calling the functions?

A) call by value B) call by reference
C) call by pointer D) none
 
Answer & Explanation Answer: B) call by reference

Explanation:

In the call by reference, it will just copy the address of the variable to access it, so it will reduce the memory in accessing it.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

15 20724
Q:

What do you mean by friend function in C++ ?

Answer

Friends can be either functions or other classes. The class grants friends unlimited access privileges.

* The declaration of the function should be preceded by the keyword 'friend'.
* The function definition will not use the keyword or the scope operator '::'.


Thus, a friend function is an ordinary function or a member of another class.

Report Error

View answer Workspace Report Error Discuss

15 3693
Q:

What is meaning of following declaration?
int(*p[5])();

A) p is pointer to function. B) p is array of pointer to function.
C) p is pointer to such function which return type is array. D) p is pointer to array of function.
 
Answer & Explanation Answer: B) p is array of pointer to function.

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

14 28852