The Gateway to Computer Science Excellence
+1 vote
68 views
#include <stdio.h> 
void demo() 
{ 
	printf("GeeksQuiz "); 
} 
int main() 
{ 
demo();
	return 0; 
}
******************************************************************************
#include <stdio.h> 

int main() 
{ 
demo();
	return 0; 
}

void demo() 
{ 
	printf("GeeksQuiz "); 

} 

 

will both program same  result?

 

in Programming by Active (1.7k points)
edited by | 68 views

2 Answers

0 votes
yes both are same,

it start the execuation o main function
by Boss (35.7k points)
0
does any one going to give error ?

I am having problem because there is no prototyping in one of them and there is no error  . I hope u understand my concern..
0
second program, have to give compilation error due to demo() doesn't declare before it's calling.

some of the compilers ( but not all ), by default assign int as return type but your original definition have void as return type., in this case also, it produce compilation error.
0
but it didn't went that way that's why I posted this question  i checked on ideone.com
0

don't trust online compilers !

check in this online compiler https://www.jdoodle.com/c-online-compiler

0

at the end we need to define function before main() if we are writing the function after main ()

is it so?

0
yes
0 votes

NO. 

If you want to define demo(); after main(), then you need to include the function definition before the main function, otherwise your code will result in an error.

#include <stdio.h>

void demo(); // function defination

int main() {
demo();
return 0;
}

void demo() {
printf("GeeksQuiz ");

}

 

by (11 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,645 questions
56,596 answers
195,824 comments
102,073 users