Professional Documents
Culture Documents
INTRODUCTION TO PROGRAMMING
The
Elements of Introduction to Keywords and
Computational Hello World in C
Programming C programming Identifiers
Process
• Understand computational
1 processes
Master software engineers have the ability to organize programs so that they can
be reasonably sure that the resulting processes will perform the tasks intended.
They can visualize the behavior of their systems in advance.
They know how to structure programs so that unanticipated problems do not lead
to catastrophic consequences, and when problems do arise, they can debug their
programs.
Well-designed computational systems, like well-designed automobiles or nuclear
reactors, are designed in a modular manner, so that the parts can be constructed,
replaced, and debugged separately.
Every powerful language has three mechanisms for combining simple ideas to
form more complex ideas:
The use of primitive expressions, which represent the simplest entities the language is
concerned with
A means of combination, by which compound elements are built from simpler ones
A means of abstraction, by which compound elements can be named and manipulated
as units.
Operands manipulated
Arithmetic by arithmetic operators
Character set is a set of alphabets, letters and some special characters that
are valid in C language.
C uses the uppercase letters A to Z, lowercase letters a to z, blank space,
the digits 0 to 9 and certain special characters as building blocks to form
basic program elements.
, < > . -
( ) ; $ :
% [ ] # ?
’ & { } “
^ ! * / |
_ \ ~ + =
A valid identifier can have letters (both uppercase and lowercase letters),
digits and underscores.
It is discouraged to start an identifier name with an underscore.
An identifier cannot be a Keyword.
Giving a meaningful name to an identifier, makes it easy for you and other
programmers to understand your code.
For example storing the age of friend using an identifier called age instead afa
A comment is a note to yourself (or others) that you put into your source
code.
All comments are ignored by the compiler. They exist solely for your
benefit.
Comments are used primarily to document the meaning and purpose of
your source code, so that you can remember later how it functions and
how to use it.
§ The Code on the next slide is an example of a simple program to get you
started in C.
In the code above it is very obvious that some of the text in there are just
comments.
Can you identify any multi-line and/or single line comments?
The program seen above displays to the screen the text “Hello World!”
To do this successfully the program needs to speak to the computer’s
hardware responsible for display.
This requires an elaborate sequence of actions. However, this heavy lifting
has been done for us and bundled in a Header File called stdio (Standard
Input/Output) header file.
The data type int that comes before the main() function is simply to cater
for the returning of the integer 0 from the statement return 0.
A lot more would be shared on the returning value when studying the topic
FUNCTIONS.
The printf( ) is a library function that sends formatted output to the screen
(displays the string inside the quotation marks).
Notice the semicolon(;) at the end of the statement.
In our program, it displays Hello, World! on the screen.
Remember, you need to include stdio.h file in your program for this to
work.
The return statement return 0; inside the main() function ends the
program.
This statement isn’t mandatory. However, it’s considered good
programming practice to use it.
You must have noticed a \n pair of characters inside the printf() function.
This pair of characters is an example of an Escape Sequence.
The combination of these characters provide a special effect. For example
the \n produces a newline (like the enter key) and the \t produces a
horizontal space (like the tab key)
\b Backspace \\ Backslash
\v Vertical tab
Contact: tsadjaidoo@knust.edu.gh
Office: Caesar Building, Room 413