C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 9)
9.
Identify which of the following are declarations
1 : extern int x;
2 : float square ( float x ) { ... }
3 : double pow(double, double);
1
2
1 and 3
3
Answer: Option
Explanation:
extern int x; - is an external variable declaration.

double pow(double, double); - is a function prototype declaration.

Therefore, 1 and 3 are declarations. 2 is definition.
Discussion:
37 comments Page 1 of 4.

Sundar said:   1 decade ago
@Swathi Bhat

double pow(double, double);

It is a function prototype declaration. It should be defined somewhere in the program module. It denotes the following

1. Function name is 'pow'
2. It should called with 2 arguments of type 'double'
3. It will return a double value as result.

If you want to call the function then use the following method:

double Result;
Result = pow(5, 4);

Hope you can understand this. Have a nice day!

Priyanka said:   1 decade ago
Hi Lipsha,

void main()
{
int num1;
display(num1);
}

void display(int para1)

{
-----------
-----------
}

In This example:

-> num1 is actual definition or actual parameter.(Parameters used in Function declaration is called actual parameters.).

-> para1 is formal definition or formal parameters.(Parameters used in Function definition is called actual parameters.).

Mallikarjunagoud said:   5 years ago
@Babi,

For a variable, declaration means just stating its data type along with giving it name for memory allocation; while definition means giving the value of that variable. The declaration is giving a prototype like simply a name. The definition is associating the task or the meaning with the prototype.

Ramarao mundru said:   1 decade ago
Hi,

file f1.c
extern int a;//declaration because it doesn't allocate memory for a variable,it has allocated memory somewhere else in the program
file f2.c
int a;// it is definition because here it is getting memory

a=3;//it is assigment

Santosh kumar said:   1 decade ago
float square ( float x ) { ... } but here it is declared and as well as can be defined so why cant we put it in the category of declaration. it comes under both declaration and definition, can any one explain me in detail?

Bhoopend said:   1 decade ago
float square(float x) {...} is both dec/def because in prototype square(float) does not reserve any space in memory as we declare square(float x) now it reserve memory for float variable x.

Jaz said:   1 decade ago
int a;
is the declaration, it simply assigns the datatype for the variable.

int a=10; is the definition, it assigns the value for the variable, the value given should match d datatype.

Sravya said:   1 decade ago
@ aishu:
declaration just assigns a data type for the variable taken..
ex: int x;
whereas definition assigns a value satisfying the data type
ex: int x=2;

Naveen goud said:   1 decade ago
@aishu

A declaration is just writing a type of variable or function.

a definition is simply assigning a values to that particular variable or function.

San said:   8 years ago
If pow is the functional means then what about pow?

Is it also expanded as the power of right? Do clearly explain anyone?


Post your comments here:

Your comments will be displayed after verification.