in GATE retagged by
992 views
0 votes
0 votes

What is the output of the following code snippet?

#include<stdio.h>
int main ( )
{
int x = 2, y = 5;
if (x < y)
   return (x = x+y);
else
   printf (“ GO Mock 1  ”);
   printf(“ Welcome to GO Mock test ”);
}
  1. GO Mock 1
  2. Welcome to GO Mock Test
  3. No output
  4. GO Mock 1Welcome to GO Mock Test
in GATE retagged by
by
992 views

1 Answer

3 votes
3 votes
Best answer
There is no compilation error but there will no output because function is returning a value and if statement is true in this case.
selected by

4 Comments

can anyone please tell what will happen after return statement??? it will halt??
0
0
main functions return to OS, that means program execution completes !
2
2

@Bikram sir, I feel "Welcome to GO Mock Test" must be printed since in the else statement there are no curly braces which implies that only the first statement preceding the else is a part of else and rest aren't considered as a part of else.
So as per this logic the second line should be printed by default.

0
0
Answer:

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

64.3k questions

77.9k answers

244k comments

80.0k users