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 2 of 2.

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

Varun said:   1 decade ago
Thank you. @Rupinderjit.

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)

Lav said:   1 decade ago
What is %p ?

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


Post your comments here:

Your comments will be displayed after verification.