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 ”); }
what is int here ? it is return type ,
in GCC we write int main() it is a good practice
if you do not write int and just write main() it is fine in GCC, as by default main() takes int in GCC :)
What will print , if "else" part of the program is in execution?
@srestha
see in this question, if condition part is true but it return some value , Not print anything ..
there will no output because function is returning a value and if statement is true in this case.
but the time runnung the code, I am getting runtime error
Why?
https://ideone.com/fGjPn6
@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.
64.3k questions
77.9k answers
244k comments
80.0k users