AllExperts > C 
Search      
C
Volunteer
Answers to thousands of questions
 Home · More C Questions · Answer Library  · Encyclopedia ·
More C Answers
Question Library

Ask a question about C
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Joseph Moore
Expertise
I've been programming in one form or another since my brother taught me BASIC when I was 6. I've been programing professionally since I was 20, first web development with HTML, JS, DHTML, CSS, etc., then I became a video game developer, writing code in C, C++, C#, SQL, assembly, and various scripting languages. I've even written my own scripting languages, custom designed for the games I was making. I also dabble in Java, PHP, and Perl. I've worked on pretty much every aspect of game development, including graphics, audio, gameplay, tool, UI, input, animation, and physics.

Experience
I've been writing C code for 12 years, both on my own in my spare time and professionally.

Organizations
IGDA

Education/Credentials
Bachelor of Science in Game Design and Development, Full Sail University, Winter Park, FL

Awards and Honors
Salutatorian and Advanced Achiever Awards at Full Sail; Independent Games Festival Student Showcase winner, 2004; Featured article on Gamasutra about an experimental game developed in 2004

 
   

You are here:  Experts > Computing/Technology > C/C++ > C > c programming

C - c programming


Expert: Joseph Moore - 2/5/2010

Question
1.what is return 0;  plz explain.
2.explain the process of compilation and execution.what is difference between them? plz explain in simple language.
3.whenever a expression contains logical and operator and logical or operator then logical and has higher priority.then why we evaluate the expression from left to right instead of firstly evaluate logical and?
ex-> x=y=z=1;
z=++x||++y&&++z;     //x=2,y=1,z=1;
                   //why not? x=1,y=2,z=1

Answer
1. A function is allowed to return a value.  When you put "return 0;" you are simply returning a value of 0.

2. Compiling code takes higher-level code (such as C or C++) and turns it into a language that the machine can understand.  The computer does not read C or C++ code, it reads machine code, which is purely binary.

Execution is taking the compiled code and running it.

3. The statement here can be considered to be something along the lines of:

 z = ++x || (++y && ++z)

However, in C and C++, there are short-circuits put into place for logical operations.  In an or statement, if the first statement is true, then it doesn't matter what the second statement is.  In an and, if the first statement is false, then it doesn't matter what the second statement is.  this is used to great advantage when dealing with pointers.  Consider the following:

int myFunc(int* input)
{
 if (input && (*input == 5))
 {
    return 1;
 }

 return 0;
}

You cannot dereference a null pointer, so the if statement first checks to see if the pointer is valid before ever checking the rest of the statement.  This keeps the code from crashing.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.