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.

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

Jayanti said:   6 years ago
Here, Segmentation fault error.

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.

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).

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

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

Prashanth said:   9 years ago
Output : Segmentation fault (core dumped).

Cheeku said:   9 years ago
It will print the address of main.

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

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

"Segmentation fault (core dumped)".


Post your comments here:

Your comments will be displayed after verification.