Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C function declaration within another function

can anyone explain these lines to me:

int xyz( void )  
{ 
extern void abc( void );
}

a function declaration within a function definition? or am I missunderstanding something?

like image 306
binaryguy Avatar asked Feb 04 '11 08:02

binaryguy


People also ask

Can we declare function inside another function in C?

Nested function is not supported by C because we cannot define a function within another function in C. We can declare a function inside a function, but it's not a nested function.

Can a function be defined within another function?

A function which is defined inside another function is known as inner function or nested functio n. Nested functions are able to access variables of the enclosing scope. Inner functions are used so that they can be protected from everything happening outside the function. This process is also known as Encapsulation .

How do you call a function inside a function in C?

Syntax to Call a Function We can call a C function just by passing the required parameters along with function name. If function returns a value, then we can store returned value in a variable of same data type. int sum = getSum(5, 7); Above statement will call a function named getSum and pass 5 and 7 as a parameter.

Does C allow nested functions?

C does not enable nested functions because we cannot define a function within another function in C. It is possible to declare a function within a function, but this is not a nested function.


1 Answers

Yes, your guess is correct. It's declaring the existence of the function abc(), so it may be referenced within xyz(). Note that the extern is unnecessary, as functions are extern by default.

like image 126
Oliver Charlesworth Avatar answered Sep 23 '22 20:09

Oliver Charlesworth