C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 11)
11.
When we mention the prototype of a function?
Defining
Declaring
Prototyping
Calling
Answer: Option
Explanation:

A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type.

While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface.

Discussion:
46 comments Page 1 of 5.

Gurpreet Sidhu said:   1 decade ago
Prototyping means declaring a function.
Now What is declaration and definition?

In term of variables:

extern int a; //It is a declaration. Declaration means variable is not present at that time in memory.It will come in memory at the time of execution.

int a; //It is a declaration as well as definition. Definition means variable is present in memory. Where extern tells the compiler that a variable of type int and named 'a' will be linked to the program at runtime.

In term of Functions:

extern int fun(); //it is a prototype which tells the compiler that a function named 'fun' which will be linked at runtime may be present in the same file or outside the file.

int fun(); //it is a prototype which tells the compiler that a function named 'fun' which will be linked at runtime will be defined in the same file.

Vineeth said:   1 decade ago
Initialization means declaration and assignment, like int a=10;

Definition means just like ... int a; here memory space is allocated by the OS at the run time , and if initialization means that value goes to the reserved memory.

Then you may have a doubt what is declaration? Isn't the statement int a; is the declaration itself? Answer is NO, int a;is defenition, int a=10; is initialization ..and the declaration is like extern int a;

Here what happens is no memory space is allocated for 'a', Its simply telling the compiler that variable 'a' is a type of 'int' and you should define it if you want to use it.. like int a; again...

Swapnil said:   1 decade ago
Declaration is the process of declaring the variable with some special name and its data-type,scope,memory storage etc. and definition is actually assining some value to that variable.

In case of function declaration is defining its prototype and declaration is code where we specify what the function actually does.

Examples:

case 1) variable

Variable Declaration:
int a,b[10];

Variable Definition:
a=1, b={1,2,3,....};


Function Declaration:
void display();

Function Definition:

void display()
{
printf("......");
}

Shivaji said:   1 decade ago
#include<stdio.h>
int funcall(int,int);//function prototyping
void main()
{
int sum=0;
int a=10,b=30;
sum=funcall(a,b);
printf("\nsum is %d",sum);
}

int funcall(a,b) //function definition
{
int cal=a+b;
printf("\ncal=%d",cal);
return cal;
}

out put: 40


Sorry prathyusha ur output is wrong that is not 10, 30 is the anws.
We have not to declare a is must that is mandetory...
y b'case we already declaring function call dat is funcall(int,int)..
any how ur explaination is good...

Thank u mr.sundar

Prathyusha said:   1 decade ago
#include<stdio.h>
int funcall(int,int);//function prototyping
void main()
{
int a,sum;
sum=funcall(10,20);
printf("sum is %d",sum);
}

int funcall(int a,int b)
{
int cal=a+b;
return cal;
}

Output: sum is 10

When compiler come across the statement: sum=funcall(10,20);
it wants to know wat type of value it will return.so at that time it will go and check whether function prototyping is given or not , to see the datatype of the parameter used by that function.

CORRECT ME IF I AM WRONG PLZ!...

Ankita said:   1 decade ago
Function Declaration and function prototyping is nothing but one and the same thing.

It was easy for programmers to call the function with incorrect.

Parameters which needless to say had disastrous runtime consequences.

Thus ANSI C mandates function prototypes as the method for function declaration.

DHANUNJAY said:   1 decade ago
Prototype is nothing but an outlook, by seeing it we can able to understand what is the matter that it is going to represent in the program. It just says the information about a particular declared variable or a function. I think your dbt was clarified.

Kavitha said:   1 decade ago
Hi tomson,
Declaration is
int a;
char b;
float c;
.....
Initialization is
a=10;
b='h';
c=1.2;

We can use both declaration and initialization at same time
int a=10;
char b='w';
......
I think so now u understand.
If you hav any other doubt ask me.

Sundar said:   1 decade ago
@Prathyusha

This type of prototype declaration requires only in old compilers. (TurboC under 16-bit DOS OS).

But in modern compilers this function prototyping is not required.
GCC, VC++, C#, etc.

Vignesh said:   7 years ago
Prototype means: Gives a function name and args types.

For eg:sum funcall (10, 20), where funcall is an prototype means function name. Where does omit about the interior body of that function.


Post your comments here:

Your comments will be displayed after verification.