How to shrink your stomach

How to shrink your stomach created by jack federbroke helpd me to loss weight so i want to feedback him for that thank you jack! How to shrink your stomach http://www.howtoshrinkyourstomach.net/

Saturday, February 25, 2012

C Language Tutorial 2.getting Started

The best way to get started with C is to actually look at a program, so load the file named
trivial.c into edit and display it on the monitor.

2.1 Your First C Program

You are looking at the simplest possible C program. There is no way to simplify this program,
or to leave anything out. Unfortunately, the program doesn’t do anything.

main()
{
}

The word "main" is very important, and must appear once, and only once, in every C program.
This is the point where execution is begun when the program is run. We will see later that this
does not have to be the first statement in the program, but it must exist as the entry point.
Following the "main" program name is a pair of parentheses, which are an indication to the
compiler that this is a function. We will cover exactly what a function is in due time. For now,
I suggest that you simply include the pair of parentheses.

The two curly brackets { }, properly called braces, are used to define the limits of the program
itself. The actual program statements go between the two braces and in this case, there are no
statements because the program does absolutely nothing. You can compile and run this program,
but since it has no executable statements, it does nothing. Keep in mind however, that it is a
valid C program.

2.2 A Program That Does Something

For a much more interesting program, load the program named wrtsome.c and display it on
your monitor. It is the same as the previous program except that it has one executable statement
between the braces.


main()
{
printf("This is a line of text to output.")
}

The executable statement is another function. Once again, we will not worry about what a
function is, but only how to use this one. In order to output text to the monitor, it is put within
the function parentheses and bounded by quotation marks. The end result is that whatever is
included between the quotation marks will be displayed on the monitor when the program is
run.

Notice the semi-colon ; at the end of the line. C uses a semi-colon as a statement terminator,
so the semi-colon is required as a signal to the compiler that this line is complete. This program
is also executable, so you can compile and run it to see if it does what you think it should. With
some compilers, you may get an error message while compiling, indicating the printf() should
have been declared as an integer. Ignore this for the moment.

2.3 Another Program With More Output

Load the program wrtmore.c and display it on your monitor for an example of more output
and another small but important concept. You will see that there are four program statements
in this program, each one being a "printf" function statement. The top line will be executed first
then the next, and so on, until the fourth line is complete. The statements are executed in order
from top to bottom.

main( )
{
printf("This is a line of text to output.\n");
printf("And this is another ");
printf("line of text.\n\n");
printf("This is the third line.\n");
}

Notice the funny character near the end of the first line, namely the backslash. The backslash
is used in the printf statement to indicate a special control character is following. In this case,
the "n" indicates that a "newline" is requested. This is an indication to return the cursor to the
left side of the monitor and move down one line. It is commonly referred to as a carriage
return/line feed. Any place within text that you desire, you can put a newline character and start
a new line. You could even put it in the middle of a word and split the word between two lines.

The C compiler considers the combination of the backslash and letter n as one character. The
exact characters used to indicate a newlin and carriage return are operating system specific.
MS-DOS, Unix, 1616/OS and Macintosh may vary one from the other.

A complete description of this program is now possible. The first printf outputs a line of text
and returns the carriage. The second printf outputs a line but does not return the carriage so the
third line is appended to that of the second, then followed by two carriage returns, resulting in
a blank line. Finally the fourth printf outputs a line followed by a carriage return and the program
is complete.

Compile and run this program to see if it does what you expect it to do. It would be a good idea
at this time for you to experiment by adding additional lines of printout to see if you understand
how the statements really work.


2.4 To Print Some Numbers

Load the file named oneint.c and display it on the monitor for our first example of how to
work with data in a C program.


main( )
{
int index;
index = 13;
printf("The value of the index is %d\n",index);
index = 27;
printf("The valve of the index = %d\n",index);
index = 10;
printf("The value of the index = %d\n",index);
}

The entry point "main" should be clear to you by now as well as the beginning brace. The first
new thing we encounter is the line containing "int index;", which is used to define an integer
variable named "index". The "int" is a reserved word in C, and can therefore not be used for
anything else. It defines a variable that can have a value from -32768 to 32767 on most MS-DOS
microcomputer implementations of C. It defines a variable with a value from -2147483648 to
2147483647 in HiTech C. Consult your compiler users manual for the exact definition for your
compiler. The variable name, "index", can be any name that follows the rules for an identifier
and is not one of the reserved words for C. Consult your manual for an exact definition of an
identifier for your compiler. In HiTech C, the construction of identifier names is the same as
in UNIX, however 31 characters and both cases are significant. The compiler prepends an
underscore to external references in the assembler pass. The final character on the line, the
semi-colon, is the statement terminator used in C.

We will see in a later chapter that additional integers could also be defined on the same line,
but we will not complicate the present situation.

Observing the main body of the program, you will notice that there are three statements that
assign a value to the variable "index", but only one at a time. The first one assigns the value of
13 to "index", and its value is printed out. (We will see how shortly.) Later, the value 27 is
assigned to "index", and finally 10 is assigned to it, each value being printed out. It should be
intuitively clear that "index" is indeed a variable and can store many different values. Please
note that many times the words "printed out" are used to mean "displayed on the monitor". You
will find that in many cases experienced programmers take this liberty, probably due to the
"printf" function being used for monitor display.


2.5 How Do We Print Numbers

To keep our promises, let’s return to the "printf" statements for a definition of how they work.
Notice that they are all identical and that they all begin just like the "printf" statements we have
seen before. The first difference occurs when we come to the % character. This is a special
character that signals the output routine to stop copying characters to the output and do something
different, namely output a variable. The % sign is used to signal the start of many different
types of variables, but we will restrict ourselves to only one for this example. The character
following the % sign is a "d", which signals the output routine to get a decimal value and output
it. Where the decimal value comes from will be covered shortly. After the "d", we find the
familiar \n, which is a signal to return the video "carriage", and the closing quotation mark.

All of the characters between the quotation marks define the pattern of data to be output by this
statement, and after the pattern, there is a comma followed by the variable name "index". This
is where the "printf" statement gets the decimal value which it will output because of the "%d"
we saw earlier. We could add more "%d" output field descriptors within the brackets and more
variables following the description to cause more data to be printed with one statement. Keep
in mind however, that it is important that the number of field descriptors and the number of
variable definitions must be the same or the runtime system will get confused and probably quit
with a runtime error.

Much more will be covered at a later time on all aspects of input and output formatting. A
reasonably good grasp of this topic is necessary in order to understand everything about output
formatting at this time, only a fair understanding of the basics.
Compile and run oneint.c and observe the output.


2.6 How Do We Add Comments In C

Load the file comments.c and observe it on your monitor for an example of how comments
can be added to a C program.


/* This is a comment ignored by the compiler */
main( ) /* This is another comment ignored by the compiler  */
{
printf("We are looking at how comments are "); /* A comment is
                                                     allowed to be
                                                     continued on
                                                     another line  */

printf("used in C.\n");
}
/* One more comment for effect */

Comments are added to make a program more readable to you but the compiler must ignore the
comments. The slash star combination is used in C for comment delimiters. They are illustrated
in the program at hand. Please note that the program does not illustrate good commenting
practice, but is intended to illustrate where comments can go in a program. It is a very sloppy
looking program.

The first slash star combination introduces the first comment and the star at the end of the first
line terminates this comment. Note that this comment is prior to the beginning of the program
illustrating that a comment can precede the program itself. Good programming practice would
include a comment prior to the program with a short introductory description of the program.
The next comment is after the "main( )" program entry point and prior to the opening brace for
the program code itself.

The third comment starts after the first executable statement and continue for four lines. This
is perfectly legal because a comment can continue for as many lines as desired until it is terminated. Note carefully that if anything were included in the blank spaces to the left of the three
continuation lines of the comment, it would be part of the comment and would not be compiled.
The last comment is located following the completion of the program, illustrating that comments
can go nearly anywhere in a C program.

Experiment with this program be adding comments in other places to see what will happen.
Comment out one of the printf statements by putting comment delimiters both before and after
it and see that it does not get printed out.

Comments are very important in any programming language because you will soon forget what
you did and why you did it. It will be much easier to modify or fix a well commented program
a year from now than one with few or no comments. You will very quickly develop your own
personal style of commenting.

Some compilers allow you to "nest" comments which can be very handy if you need to "comment
out" a section of code during debugging. Check your compiler documentation for the availability
of this feature with your particular compiler. Compile and run comments.c at this time.


2.7 Good Formatting Style

Load the file goodform.c and observe it on your monitor.

/*main() /* Main program starts here  
{
printf("Good form");
printf ("can aid in ");
printf ("understanding a program.\n");
printf("And bad form ");
printf ("can make a program ");
printf ("unreadable.\n");
}

It is an example of a well formatted program. Even though it is very short and therefore does
very little, it is very easy to see at a glance what it does. With the experience you have already
gained in this tutorial, you should be able to very quickly grasp the meaning of the program in
it’s entirety. Your C compiler ignores all extra spaces and all carriage returns giving you
considerable freedom concerning how you format your program. Indenting and adding spaces
is entirely up to you and is a matter of personal taste. Compile and run the program to see if it
does what you expect it to do.

Now load and display the program uglyform.c and observe it.

main( ) /* Main program starts here */{printf("Good form ");printf
("can aid in ");printf(" understanding a program.\n")
;printf("And bad form ");printf("can make a program ");
printf("unreadable.\n");}

How long will it take you to figure out what this program will do? It doesn’t matter to the
compiler which format style you use, but it will matter to you when you try to debug your
program. Compile this program and run it. You may be surprised to find that it is the same
program as the last one, except for the formatting. Don’t get too worried about formatting style
yet. You will have plenty of time to develop a style of your own as you learn the language. Be
observant of styles as you see C programs in magazines, books, and other publications.

This should pretty well cover the basic concepts of programming in C, but as there are many
other things to learn, we will forge ahead to additional program structure.


2.8 Programming Exercises

1. Write a program to display your name on the monitor.
2. Modify the program to display your address and phone number on separate lines by adding
two additional "printf" statements.


next lesson

C Language Tutorial 3. Program Control







No comments:

Post a Comment

App creators your key for sucsses








If you can click a mouse, you can
profit from online video!
Recent news articles show how some YouTubers are earning upwards of $100,000 per year from the ads they display on and around their videos...

What if you could earn money from those ads, without actually creating the content?
YOU CAN!

 

All you need to know in one place

Small step for huge knowledge
 
 
This is the place you learn everything you need to move forward and become the leader in programming and creating mobile apps.

No need to be an expert anyone can start from scratch !

You just need to find the area that interests you and access, from there the way to success is up to you .

Good Luck!

















 Click Here App Creators






App creators


guidescollection

i want to know

hello everyone

i wanted to ask from the viewers

if ther any subject thet you read and want continue reading and its not completed yet please let me know by comment or email

or if ther any subject thet you want me to add pls let me know