in Programming in C
250 views
0 votes
0 votes

What happens if there are more than 1 return statements in a function?

in Programming in C
250 views

1 Answer

3 votes
3 votes
Best answer

only first return will get executed .After which the control will be transferd back

#include<stdio.h>

int fun()
{
return 5+2;
return 5-1;
}

int main() {

    printf("%d ", fun());
	return 0;
}

Here output will be 7 . The will execute successfully witout any error

selected by
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