C Programming - Functions - Discussion

Discussion Forum : Functions - Point Out Correct Statements (Q.No. 1)
1.
Which of the following statements are correct about the program?
#include<stdio.h>

int main()
{
    printf("%p\n", main());
    return 0;
}
It prints garbage values infinitely
Runs infinitely without printing anything
Error: main() cannot be called inside printf()
No Error and print nothing
Answer: Option
Explanation:

In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.

Discussion:
15 comments Page 1 of 2.

Gourav said:   8 years ago
In this question, main() is called recursively & for each call of main() the memory is allocated in stack & when the stack gets full the pointer which allocates memory will reach in another segment & it will give Segmentation fault (core dumped).

Dawood Ibrahim Bhat said:   7 years ago
Will run infinitely, but STACK-OVERFLOW will occur as the main () is being called continuously and control is not going back to the calling function.

Rupinderjit said:   1 decade ago
%p is used to print the address of some variable as used by the host computer.It can be Hex Binary BCD unsigned or any.
(1)

Dhiraj said:   1 decade ago
Why it does not print 0 infinite times ? When stack overflows main return 0 and that value get printed.

Krishanu said:   1 decade ago
Again I want to say that the actual output will be:

"Segmentation fault (core dumped)".

Ankur said:   1 decade ago
it generate error becouse main function can not call inside the main() function.

Asish panigrahi said:   9 years ago
%p has no value so that it prints infinite garbage value.

Yamini said:   8 years ago
I didn't understand. Please give us a clear explanation.

SAHA said:   4 years ago
%p is used to printing the address of a pointer.

Lakshmi said:   1 decade ago
What is the meaning of "Segmentation fault"?


Post your comments here:

Your comments will be displayed after verification.