Dev C++

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Comment

//: this is what a comment look like. You should have your name after a first comment then enter. Place a second comment then write today's date, then another comment then the title of the assignment.

Running the program

After you done when you run this code it will say on the screen " your age is 10". the 10 come from me assigning a value to this variable called age. *So the ( "Your age is %d", age); statement from the printf statement, since your write the , %d" , age in the statement it pulled the age 10 you we type from the Int age = 10 statement above. That is why the int age = 10 is memory location.

The If statement

As dicuss from the flogarithms part, the if statement have 2 side to it. To get both side we will write if ( age > 30 ): this is the if statement. We will then write printf ( "You are old "); this is the first condition if your age is less than 30 then the screen will display your are young. * We will then type else, the else states that there are 2 condition. * Then after the else you will type the other condition, which is printf( "you are young");. This will be display on the screen if you type a number that is less than 30 as your answer. * Then you type return 0

Scanf

If you want to give the option for the user to put in their age and to have a if statement just like from the last example with the flogarithms, you won't need to put the 10 after the int age; * Instead of the ( "Your age is %d", age); after the printf, you will simply want to put ( "Enter your age; ") ; because there is no memory that is involve, the reason that there was no memory involve is because the you did not assign a variable after the int age. * The Scanf does require a memory address ( &age) not just a variable name.

white spaces

In programming spaces up or right is ignore. Like if you press enter to time and the cursor went down 2 spaces, those spaces means nothing. The same applies for spaces to the right. It is just there for readability. In python spaces means something.

The main function

Int main ( ) { you should always have this function after the main function. The main is the function the operating system look for or called for. Another name for it is the main entry point. * The parenthesis are for parameters, when you see a main and follow by a parathesis, that is a function. * The brakcet indicates the body of the function, meaning that every in between the bracket belong to the function main. * The main entry point does nothing to the code, it's just there as a comment and we know that comments is just there to explain the function to the viewer. so you don't have to have them there.

Printf ( "Your age is %d", age);

Printf ( "Your age is %d", age); . The %d" , age is the format specifier, that say that your age is going to be displayed and you will inject ad value in. * The ; indicates that the statement ends. The ; say to the operating system that I'm done with this statement and go ahead and execute it.

Return 0

You should always have a return 0; after the int main. The return 0 is sent back to the operating system and the 0 means that everything went well nothing was wrong. If there's an error code, the 0 may be -100 then the operating system will know what to do with it.

#include <stdio.h>

You should always have this. This is the main library that we have to bring in.

Declare a variable

to declare a variable in C, we type int age; ( the int age does not have to be in italic) . The int is the data type and the age is the variable we want to use or identifier that points to memory address. You can have whatever data type and variable you want to. * For this example we will use 10 as the variable. We are assigning 10 to this variable age.


संबंधित स्टडी सेट्स

Kin. Muscles on the Shoulder Girdle

View Set

Exam 4 - Med-Surg Success Questions; Breast Disorders, Endocrine & Some GI

View Set

Ch. 12 Pregnancy at risk: Gestational conditions

View Set

Chapter 50 (Muscle and Skeleton)

View Set

Sociology Ch. 4: Socialization and the Life Course

View Set

11.2 market manipulation and insider trading

View Set