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
if(!printf("hello")) printf("hello"); else printf("world"); Source: CoolInterview.com
Answered by: Ramanjaneyulu Reddy | Date: 3/11/2008
| 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
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
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
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
main() { if(printf("hello")==0) printf("hello"); else printf("world"); } Source: CoolInterview.com
Answered by: madhu | Date: 6/29/2009
| 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
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
#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
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
#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
#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
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
main() { if(printf("hello")==0) printf("hello"); else printf("world"); } Source: CoolInterview.com
Answered by: juned khan | Date: 8/20/2009
| 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
if(!fork()) { printf("hello"); } else { printf("world"); } Source: CoolInterview.com
Answered by: srinivas | Date: 8/24/2009
| 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
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
#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
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
#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
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
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
#include<stdio.h> main() { if(1) printf(" hello"); else printf(" world"); } Source: CoolInterview.com
Answered by: ranjith | Date: 9/7/2009
| Contact ranjith
if(printf("hello")) { printf("world"); } Source: CoolInterview.com
Answered by: vallari | Date: 9/11/2009
| 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
#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
void main() { if(1) { printf("Hello"); goto label; } else { label: printf("World"): } } Source: CoolInterview.com
Answered by: karthik | Date: 9/25/2009
| 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
only this much is sufficient: if(printf("hello")) { printf("world"); } Source: CoolInterview.com
Answered by: Surbhi | Date: 9/29/2009
| Contact Surbhi
if((printf("hello"))==0) printf("hello"); else printf("world"); Source: CoolInterview.com
Answered by: Uk | Date: 10/4/2009
| 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
int main() { if( !printf("hello")); else printf("world"); } Source: CoolInterview.com
Answered by: pearl | Date: 10/20/2009
| 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
if(!printf("Hello")) { prinf("Hello") } else { printf("World") } Source: CoolInterview.com
Answered by: Rakesh | Date: 10/25/2009
| Contact Rakesh
if(!printf("hello")) { printf("HELLO") } else { printf("world") } Source: CoolInterview.com
Answered by: NAVEED | Date: 10/27/2009
| 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
#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
#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
main() { if(0) printf("hello"); else printf("world"); } Source: CoolInterview.com
Answered by: vishnu | Date: 11/20/2009
| 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
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
if( printf("Hello") == 0 ) { } else { printf("World"); } Source: CoolInterview.com
Answered by: Komal | Date: 12/8/2009
| Contact Komal
if(1) printf("hello"); else prinf("word"); Source: CoolInterview.com
Answered by: Bhaskar Singh | Date: 12/12/2009
| 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
#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
main() { if(printf("Hello")==0) { printf("Am"); } else { printf("World") } } output:- HelloWorld Source: CoolInterview.com
Answered by: Ruchi | Date: 12/31/2009
| 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
main() { if((printf("Hello")==0)) printf(""); else printf("World"); } Source: CoolInterview.com
Answered by: kamal | Date: 1/27/2010
| 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
#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
main() { if((printf("Hello")==0)) printf(""); else printf("World"); } Source: CoolInterview.com
Answered by: sanpeep kumar | Date: 2/15/2010
| Contact sanpeep kumar
if(printf("hello")) printf("world"); Source: CoolInterview.com
Answered by: RAJU SAHANI | Date: 2/20/2010
| 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
#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
if( printf("Hello") == 0 ) { } else { printf("World"); } Source: CoolInterview.com
Answered by: ashutosh | Date: 3/28/2010
| 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
if(4-printf("hello")) { printf("hello"); } else { printf("world"); } Source: CoolInterview.com
Answered by: Manisuriya | Date: 3/31/2010
| 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
#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`
#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
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
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
#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
#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
#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
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
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
#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
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.
|