Thread: plz explain output of this program

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    74

    plz explain output of this program

    Code:
    void main(){
    	int a;
    	a=5;
    	if(a=15)
    	printf("welcome%d",a);
    	else
    	printf("hello%d"a);
    }

    why output is welcome15 ?

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    Because "a=15" and "a==15" do very different things...
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Aug 2015
    Posts
    74
    but what exactly a=1 do? i know what the function == does but what about = ? how it works?

  4. #4
    Registered User
    Join Date
    Aug 2015
    Posts
    74
    can anyone give me your whatsapp number ? so i can ask and explain you more briefly?
    i have a list of unsolved programs who want to help me?
    that programs are easy... just of 5 or 6 lines so experts can solve in within 10 min.
    plz guys reply....im waiting...
    Last edited by san12345; 02-27-2016 at 06:46 AM.

  5. #5
    Registered User
    Join Date
    Feb 2016
    Posts
    2
    Hi San,

    '=' is assignment operator(It will put the value form RHS to LFS).

    '==' is comparison operator.(It will compair the RHS and LHS value. If the value matches then only it will be true. else It won.t be true.

    Here in your case a = 15 is assigning 15 to a. So, because of this assignment the condition in if will always be true. You are getting welcome15.



  6. #6
    Registered User
    Join Date
    Aug 2015
    Posts
    74
    ohh yes!! thx for reply

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,417
    Quote Originally Posted by san12345
    i have a list of unsolved programs who want to help me?
    that programs are easy... just of 5 or 6 lines so experts can solve in within 10 min.
    Why do you have this list of "unsolved" programs? What is your goal behind getting people to "solve" these programs for you?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Aug 2015
    Posts
    74
    I want to bring out of marks in my collage exam
    So I want to learn c program from basic
    That's why I'm asking questions

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,417
    Quote Originally Posted by san12345
    I want to bring out of marks in my collage exam
    So I want to learn c program from basic
    That's why I'm asking questions
    I suggest that you take a more structured approach to basic learning: work through an introductory book or tutorial. At the moment, you seem to lack the fundamental skills to be able to investigate these problems successfully. Therefore, you will only end up getting piecemeal trivia that is unlikely to help you actually develop programming problem solving skills.

    After properly going through structured introductory material, you should have the skill to be able to solve many of these problems by yourself. At that point, for those problems that you cannot solve or are unsure of the solution, you can come back here, explain what you tried, and then get useful feedback.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plz explain output of this program
    By san12345 in forum C Programming
    Replies: 10
    Last Post: 02-26-2016, 01:03 PM
  2. Simple c program-please explain output.
    By hitesh.incept in forum C Programming
    Replies: 6
    Last Post: 09-13-2012, 12:04 PM
  3. what is the program output please explain
    By sunil17 in forum C Programming
    Replies: 2
    Last Post: 09-02-2010, 08:34 AM
  4. plz explain the output of the program.
    By raj_ksrt in forum C++ Programming
    Replies: 2
    Last Post: 05-26-2008, 03:43 AM
  5. Explain the output of the C program
    By abacus00 in forum C Programming
    Replies: 0
    Last Post: 03-24-2003, 06:24 PM