6,474 views
5 votes
5 votes

Which one of the following is correct about the statements given below?

  1. All function calls are resolved at compile time in C lang
  2. All function calls are resolved at compile time in C++ lang
  1. Only II is correct
  2. Both I and II are correct
  3. Only I is correct
  4. Both I and II are incorrect

2 Answers

Best answer
13 votes
13 votes

Consider here:

int (*p) ();
scanf("%d", &a);
if(a)
    p = fun1;
else
    p = fun2;
int b = (*p)();

This is an example of run time resolution of function calls in C. This is also applicable for C++ though it has other dynamic resolution via virtual functions. So, answer should be D. 

selected by
5 votes
5 votes

(1) C supports only "Early Binding" in which all the functions related to their function calls are resolved at compile time.

(2)C++ Supports both "Early Binding" and "Late Binding".Late Binding is the process of resolving functions related to function calls during Run time.

In C++ virtual calling mechanisms are resolved at run-time.

Hence,Option(c)only 1 correct.

Answer:

Related questions

7 votes
7 votes
2 answers
1
sourav. asked Jul 3, 2016
7,520 views
What will be output of the following program? Assume that you are running this program in little-endian processor.#include<stdio.h int main() { short a=320; char *ptr; pt...
4 votes
4 votes
4 answers
2
sourav. asked Jul 3, 2016
4,011 views
What is the output of this C code?#include<stdio.h void main() { int k=5; int *p=&k; int m=&p; printf("%d %d %d",k,*p, m); }5 5 5 5 5 junk5 junk junkcompile time error
64 votes
64 votes
15 answers
3
Arjun asked Jul 6, 2016
37,077 views
Consider the following segment of C-code:int j, n; j = 1; while (j <= n) j = j * 2;The number of comparisons made in the execution of the loop for any $n 0$ is:$\lceil \...
8 votes
8 votes
2 answers
4
Arjun asked Jul 6, 2016
3,900 views
A simple two-pass assembler does which of the following in the first pass:Checks to see if the instructions are legal in the current assembly modeIt allocates space for t...