Sponsored Links

Interview Questions



INTERVIEW QUESTIONS C BRANCHES & LOOPS IN C DETAILS

Question: if "condition"
printf("Hello");
else
printf("World")

what should be the condition,
so the output will be HelloWorld.

Answer: if(!printf("hello"))
printf("hello");
else
printf("world");

Category Branches & Loops in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.4) By 7243 users
Added on 9/28/2012
Views 72481
Rate it!

Question: if "condition"
printf("Hello");
else
printf("World")

what should be the condition,
so the output will be HelloWorld.


Answer:

if(!printf("hello"))
printf("hello");
else
printf("world"); Source: CoolInterview.com

Answered by: pushpak | Date: 10/2/2007 | Contact pushpak Contact pushpak

if(!printf("hello"))
printf("hello");
else
printf("world"); Source: CoolInterview.com

Answered by: Ramanjaneyulu Reddy | Date: 3/11/2008 | Contact Ramanjaneyulu Reddy Contact Ramanjaneyulu Reddy

second answer is wrong.
modified program is
#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("world");
else
printf("world");
} Source: CoolInterview.com

Answered by: anil | Date: 8/25/2008 | Contact anil Contact anil

second answer is wrong.
modified program is
#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("world");
else
printf("world");
} Source: CoolInterview.com

Answered by: viswanath.n | Date: 6/7/2009 | Contact viswanath.n Contact viswanath.n

main()
{
int i=0;
if(i==0)
printf("hello");

else
printf("");
printf("world");
getch();
}
Source: CoolInterview.com

Answered by: sanjay | Date: 6/11/2009 | Contact sanjay Contact sanjay

main()
{
int i=0;
if(i==0)
printf("hello");

else
printf("");
printf("world");
getch();
}
Source: CoolInterview.com

Answered by: vijay pratap | Date: 6/18/2009 | Contact vijay pratap Contact vijay pratap

main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: madhu | Date: 6/29/2009 | Contact madhu Contact madhu


program is:
#include<stdio.h>
void main()
{
if(printf("helo")!=0 && printf("world")!=0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: krishna rao | Date: 7/19/2009 | Contact krishna rao Contact krishna rao

second and third are wrong
The right answer is
#include<stdio.h>
main()
{
if(printf("hello")!=5)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: Srinivasa Rao Dama | Date: 7/23/2009 | Contact Srinivasa Rao Dama Contact Srinivasa Rao Dama

#include<stdio.h>
main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: Vikas Kanade | Date: 7/24/2009 | Contact Vikas Kanade Contact Vikas Kanade

both the posts are wrong ...
u cannot change the question
my friend....
here is the answer....having 4yers of c experiance....take it


#include<stdio.h>
int main()
{
if( printf("hello")-5 )
printf("hello");
else
printf("world");
}
as printf returns number of characters it has printed it will return 5 and minius 5 we get 0 ..it will not enter the if condition but hello will be printed and obvious it goes to else part and world is printed Source: CoolInterview.com

Answered by: spartan | Date: 7/25/2009 | Contact spartan Contact spartan

#include<stdio.h>
main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: Shiv Deepak | Date: 7/26/2009 | Contact Shiv Deepak Contact Shiv Deepak

#include<stdio.h>
main()
{
if(printf("hello") && 0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: Shiv Deepak | Date: 7/26/2009 | Contact Shiv Deepak Contact Shiv Deepak

main()
{
clrscr();
if(printf(“Hello “) == 0)
printf(“Hello”);
else
printf(“World”);
getch();
}
Source: CoolInterview.com

Answered by: Jitendra Moon | Date: 8/15/2009 | Contact Jitendra Moon Contact Jitendra Moon

main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: juned khan | Date: 8/20/2009 | Contact juned khan Contact juned khan

in linux answer is
if(!fork())
{
printf("hello");
}
else
{
printf("world
");
} Source: CoolInterview.com

Answered by: srinivas | Date: 8/24/2009 | Contact srinivas Contact srinivas

if(!fork())
{
printf("hello");
}
else
{
printf("world");
} Source: CoolInterview.com

Answered by: srinivas | Date: 8/24/2009 | Contact srinivas Contact srinivas

THIS IS CORRECT ANSWER.....


#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("world");
else
printf("world");
} Source: CoolInterview.com

Answered by: SACHEEN | Date: 8/26/2009 | Contact SACHEEN Contact SACHEEN

In 3 rd Question he changed Question itself..so wrong

correct one is.....>
#include<stdio.h>
#include<conio.h>
main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
getch();
} Source: CoolInterview.com

Answered by: subbu@nitk | Date: 8/29/2009 | Contact subbu@nitk Contact subbu@nitk

#include<stdio.h>
main()
{
if(printf("Hello")==0)
printf("Hello");
else
printf("World");
} Source: CoolInterview.com

Answered by: Subho | Date: 8/29/2009 | Contact Subho Contact Subho

Second answer is perfect.

#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("hello");
else
printf("world");
}

While checking for if condition, "hello" gets printed. And As if condition is evaluated as False, "World" gets printed. As a result the output is "helloworld" Source: CoolInterview.com

Answered by: Chaitanya Madala | Date: 8/30/2009 | Contact Chaitanya Madala Contact Chaitanya Madala

#include<stdlib.h>
#include<stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if(pid !=0 )
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: Saurabh Khare | Date: 9/1/2009 | Contact Saurabh Khare Contact Saurabh Khare

void main()
{
clrscr();
if(printf("HELLO ")==0)
{
printf("hello");
}
else
{
printf("WORLD");
}
getch();
}

I thnk it works......
ashwa Source: CoolInterview.com

Answered by: ashwa | Date: 9/2/2009 | Contact ashwa Contact ashwa

The 3rd answer is not in accordance with the question,
It should have been:
if(printf("Hello") == 0)
printf("Hello");
else
printf("World");
Source: CoolInterview.com

Answered by: Prabhath Kudaithur | Date: 9/7/2009 | Contact Prabhath Kudaithur Contact Prabhath Kudaithur

#include<stdio.h>
main()
{
if(1)
printf("
hello");
else
printf("
world");
}
Source: CoolInterview.com

Answered by: ranjith | Date: 9/7/2009 | Contact ranjith Contact ranjith

if(printf("hello"))
{
printf("world");
} Source: CoolInterview.com

Answered by: vallari | Date: 9/11/2009 | Contact vallari Contact vallari

#include<stdio.h>
main()
{
if(5-printf("hello"))
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: nikil | Date: 9/15/2009 | Contact nikil Contact nikil

#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("world");
else
printf("world");
}
Source: CoolInterview.com

Answered by: srinivasan | Date: 9/19/2009 | Contact srinivasan Contact srinivasan

void main()
{
if(1)
{
printf("Hello");
goto label;
}
else
{
label:
printf("World"):
}
} Source: CoolInterview.com

Answered by: karthik | Date: 9/25/2009 | Contact karthik Contact karthik

if(!fork())
printf("Hello");
else
printf("World");

Cool. Create a child process. Source: CoolInterview.com

Answered by: Prakash | Date: 9/27/2009 | Contact Prakash Contact Prakash

only this much is sufficient:
if(printf("hello"))
{
printf("world");
} Source: CoolInterview.com

Answered by: Surbhi | Date: 9/29/2009 | Contact Surbhi Contact Surbhi

if((printf("hello"))==0)
printf("hello");
else
printf("world"); Source: CoolInterview.com

Answered by: Uk | Date: 10/4/2009 | Contact Uk Contact Uk

#include<stdio.h>
void main()
{
if(1)
printf("Hello");
else
printf("World");
getch();
} Source: CoolInterview.com

Answered by: Nagaraj | Date: 10/10/2009 | Contact Nagaraj Contact Nagaraj

int main()
{
if( !printf("hello"));
else
printf("world");
} Source: CoolInterview.com

Answered by: pearl | Date: 10/20/2009 | Contact pearl Contact pearl

//Correct Answer//

#include <stdio>

main(){
if((printf("Hello"))==0)
printf("Hello");
else
printf("World");
}

Output is HelloWorld Source: CoolInterview.com

Answered by: Pradeep Jain | Date: 10/21/2009 | Contact Pradeep Jain Contact Pradeep Jain

if(!printf("Hello"))
{
prinf("Hello")
}
else
{
printf("World")
} Source: CoolInterview.com

Answered by: Rakesh | Date: 10/25/2009 | Contact Rakesh Contact Rakesh

if(!printf("hello"))
{
printf("HELLO")
}
else
{
printf("world")
} Source: CoolInterview.com

Answered by: NAVEED | Date: 10/27/2009 | Contact NAVEED Contact NAVEED

#include<stdio.h>
main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
}

Source: CoolInterview.com

Answered by: lovely baghla | Date: 11/5/2009 | Contact lovely baghla Contact lovely baghla

#include<stdio.h>
void main()
{
if(printf("hello")!=0)
printf("world");
else
printf("world");
}

Source: CoolInterview.com

Answered by: yashaswini | Date: 11/6/2009 | Contact yashaswini Contact yashaswini

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();

if(printf("hello")!=0)
printf("world");
/*else
printf("world"); */
getch();
}
it works Source: CoolInterview.com

Answered by: wilson | Date: 11/14/2009 | Contact wilson Contact wilson

main()
{
if(0)
printf("hello");
else
printf("world");
}
Source: CoolInterview.com

Answered by: vishnu | Date: 11/20/2009 | Contact vishnu Contact vishnu

void main()
{
clrscr();
if(printf("hell0")==5)
printf("world");
}
explanation:
here lengh of thr string "hello"
is 5. if condition is true so
world is printed Source: CoolInterview.com

Answered by: rajashekar | Date: 12/4/2009 | Contact rajashekar Contact rajashekar

void main()
{
int i;
if(i=1)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: manish choudhary | Date: 12/8/2009 | Contact manish choudhary Contact manish choudhary

if( printf("Hello") == 0 )
{
}
else
{
printf("World");
}

Source: CoolInterview.com

Answered by: Komal | Date: 12/8/2009 | Contact Komal Contact Komal

if(1)
printf("hello");
else
prinf("word"); Source: CoolInterview.com

Answered by: Bhaskar Singh | Date: 12/12/2009 | Contact Bhaskar Singh Contact Bhaskar Singh

if(!printf("Hello"))
;/*NULL statment
else
printf("World"); Source: CoolInterview.com

Answered by: Balkrishna Kelkar | Date: 12/16/2009 | Contact Balkrishna Kelkar Contact Balkrishna Kelkar

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
if(printf("hello")==0)
printf("world");
else
printf("world");
getch();
}
Source: CoolInterview.com

Answered by: vinod kumar | Date: 12/29/2009 | Contact vinod kumar Contact vinod kumar

main()
{
if(printf("Hello")==0)
{
printf("Am");
}
else
{
printf("World")
}
}
output:- HelloWorld Source: CoolInterview.com

Answered by: Ruchi | Date: 12/31/2009 | Contact Ruchi Contact Ruchi

void main()
{
if(printf("HELLO"))
printf("WORLD");
else
printf("WORLD");
getch();
}

here what exactly if(printf("HELLO") does...is that it counts the number of letters in string inside the double quotes...u can check this by writing the statement
printf("%d",printf("HELLO"));
Source: CoolInterview.com

Answered by: Vikram Ojhs | Date: 1/18/2010 | Contact Vikram  Ojhs Contact Vikram Ojhs

main()
{
if((printf("Hello")==0))
printf("");
else
printf("World");
} Source: CoolInterview.com

Answered by: kamal | Date: 1/27/2010 | Contact kamal Contact kamal

#include <stdio.h>
void main()
{
if(1);
printf("hello");
else
printf("world");
}

Source: CoolInterview.com

Answered by: Abhijeet Aute | Date: 2/1/2010 | Contact Abhijeet Aute Contact Abhijeet Aute

#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
if(i==0)
{
printf("Hello ");
goto s;
}
else
{
s:
printf("World.");
}
getch();
} Source: CoolInterview.com

Answered by: Sumaiya Ansari | Date: 2/7/2010 | Contact Sumaiya Ansari Contact Sumaiya Ansari

main()
{
if((printf("Hello")==0))
printf("");
else
printf("World");
} Source: CoolInterview.com

Answered by: sanpeep kumar | Date: 2/15/2010 | Contact sanpeep kumar Contact sanpeep kumar

if(printf("hello"))
printf("world"); Source: CoolInterview.com

Answered by: RAJU SAHANI | Date: 2/20/2010 | Contact RAJU SAHANI Contact RAJU SAHANI

#include<stdio.h>
#include<conio.h>
int main(void)
{
clrscr();
if (1)
{
printf("hello");
goto next;
}
else
{
next:
printf("world");
}
while(!kbhit());
return 0;
}
Source: CoolInterview.com

Answered by: varun tyagi | Date: 3/3/2010 | Contact varun tyagi Contact varun tyagi

#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("hello");
else
printf("world");
}

here first hello will be printed than for if condition it wont work than it will print world Source: CoolInterview.com

Answered by: anil panigrahi,jitm | Date: 3/6/2010 | Contact anil panigrahi,jitm Contact anil panigrahi,jitm

if( printf("Hello") == 0 )
{
}
else
{
printf("World");
}
Source: CoolInterview.com

Answered by: ashutosh | Date: 3/28/2010 | Contact ashutosh Contact ashutosh

void main()
{
if(printf("hello")==0)
printf("c skills");
else
printf(" world");
getch();
} Source: CoolInterview.com

Answered by: ms | Date: 3/30/2010 | Contact ms Contact ms

if(4-printf("hello"))
{
printf("hello");
}
else
{
printf("world");
} Source: CoolInterview.com

Answered by: Manisuriya | Date: 3/31/2010 | Contact Manisuriya Contact Manisuriya

if(a==3)
{
printf("hello");
goto a;
}
else
{
a:
printf("world");
} Source: CoolInterview.com

Answered by: Manisuriya | Date: 3/31/2010 | Contact Manisuriya Contact Manisuriya

#include<stdio.h>
main()
{
if(printf("HELLO"))
printf("World");
} Source: CoolInterview.com

Answered by: Tanesha voly mohammed` | Date: 4/4/2010 | Contact Tanesha voly mohammed` Contact Tanesha voly mohammed`

#include<stdio.h>
void main()
{
if(printf("hello")!=0)
{
printf("world");
}
else
printf("hello");
} Source: CoolInterview.com

Answered by: shiva kumar | Date: 4/13/2010 | Contact shiva kumar Contact shiva kumar

i=0;
if(printf("hello")!==0) && (printf("world")!==0)

printf("hello world");
else
printf("world");

Source: CoolInterview.com

Answered by: Vishal | Date: 4/14/2010 | Contact Vishal Contact Vishal

hi guys i am new to this forum..let me produce my attempt b4 u all.kindly reply back if any wrong in it..

for(i = 0;i <2;i++)
{

if(i== 0)
{
printf("hello");

i++;
}
else
{
printf('world');
}


} Source: CoolInterview.com

Answered by: Muthukumaran | Date: 5/10/2010 | Contact Muthukumaran Contact Muthukumaran

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
if(printf("HELLO")!=5)
printf("HELLO");
else
printf("WORLD");
getch();
} Source: CoolInterview.com

Answered by: debabrata swain | Date: 5/21/2010 | Contact debabrata swain Contact debabrata swain

#include<stdio.h>
main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: krish | Date: 6/30/2010 | Contact krish Contact krish



#include<stdio.h>
main()
{
if(printf("hello")!=0)
printf("hello");
else
printf("world");
}

While checking for if condition, "hello" gets printed. And As if condition is evaluated as False, "World" gets printed. As a result the output is "helloworld" Source: CoolInterview.com

Answered by: ajeet Verma | Date: 7/25/2010 | Contact ajeet Verma Contact ajeet Verma

most compact solution:-
#include<stdio.h>
main()
{
if(printf("hello"))
printf("world");
else
printf("world");
getch();
} Source: CoolInterview.com

Answered by: shashank kumar | Date: 7/28/2010 | Contact shashank kumar Contact shashank kumar

the most appropriate answer:-
main()
{
if(printf("hello")==0)
printf("hello");
else
printf("world");
getch();
} Source: CoolInterview.com

Answered by: shashank kumar | Date: 7/29/2010 | Contact shashank kumar Contact shashank kumar

#include<stdio.h>
void main()
{
if(!printf("hello"))
printf("hello");
else
printf("world");
} Source: CoolInterview.com

Answered by: Amar | Date: 8/27/2010 | Contact Amar Contact Amar


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
C Program to print the following series:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
View Answer
fibbonaci series program

View Answer
why n++ executes faster than n+1?


View Answer
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}


else
View Answer
x) main()
{
printf("%x",-1<<4);
}


}


- Branches & Loops in C Interview Questions & Answers"> View Answer
How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)

View Answer
Can include files be nested?
View Answer
Is NULL always defined as 0?
View Answer
Which expression always return true? Which always return false?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Branches & Loops in C Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2024 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions