answersLogoWhite

0

What is prototyping in c plus plus?

Updated: 8/10/2023
User Avatar

Wiki User

14y ago

Best Answer

A prototype in C++, as well as in C, is a declaration of a function and its parameters, including the types of the function and parameters. It does not actually create (define) the code for the function - it only identifies (declares) it to the compiler.

It is used to enforce type checking for functions and parameters, and it is used to declare the function for use in other code prior to the function actually being defined, such as in a different compilation unit or library. Headers, for instance, contain mostly prototypes.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Prototyping is the declaration of a function, its type, and the type and number of its arguments. The compiler uses the prototype to enforce type checking for the arguments of a function. In the case of C++, the compiler can also use the prototype to choose between two functions of the same name, differing in return value or type/number of arguments.

There are two ways to prototype. 1.) You can declare and define a function before you use it. That is automatic prototyping. 2.) You can declare a function before you use it and then define it later. That is explicit prototyping.

// example for automatic

int myfunction (int a) { // declaration and definition

return a;

}

int main (int argc, char *argv[]) {

int b = myfunction(1); // use

return 0;

}

//example for explicit

int myfunction (int a); // declaration

int main (int argc, char *argv[]) {

int b = myfunction(1); // use

return 0;

}

int myfunction (int a) { // definition

return a;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Lets start it with level zero ok...

now take printf() function.

the header file (.h file) defines it is defined as

prototype/signature : prinf()

body :body

function call : how the function is called.

now suppose i want to create a function, say add() to add to numbers,

the source file will look like :

#include /*header file included*/

#int add (int,int) /* prototype */

main() /*the calling function*/

{

int a,b; /*variables declared*/

printf("Enter two numbers ");

printf("%d%d",&a,&b);

printf("\n Addition is %d",add(a,b));

} /*main() -the calling function ends here*/

{ /*body or definition for add() function starts here*/

int add (int x,int y); /*this defines that x and y should be int*/

return x+y;

}

here main() is the calling function and add() is the called function

hope it will help you ;-)

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

There is no keyword 'prototype' in the C Programming language itself. The term "function prototype" is defined in the C language specification as "a declaration of a function that declares the types of its parameters".

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is prototyping in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is prototyping mandatory in c?

Prototyping is optional in C, though highly recommended.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


Distinguish between C programming and BASIC programming?

C is a systems language for precise, concrete development. BASIC and its derivatives are teaching and prototyping languages for rapid, abstract development.


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


Primary and secondary key in c and c plus plus?

There are no "primary and secondary keys" in c and c plus plus.


What are the advantages and disadvantages of prototyping model?

One advantage of prototyping is the fact that you can make changes to the model before building the actual model. One disadvantage of prototyping is that it can take too long.


What is c plus C plus C answer in algebra?

3c


Does 3D Systems make rapid prototyping equipment?

3D Systems sells rapid prototyping equipment


What is the different between turbo c plus plus and unix c plus plus?

There is no such thing as 'unix C++'.