C - Programming Lect 1,2,3,4
C - Programming Lect 1,2,3,4
Programming
C Programming
● Before going and reading the structure of C programs we need to have basic
knowledge of the following :
1. C’s Character Set
2. C’s Keywords
3. The General Structure of a ‘C’ Program
4. How to End a Statement
5. Free Format Languages
6. Header file & Library Functions
C’s Character Set
● “Keywords” are words that have that have special meanings to the compiler.
a compiler is a computer program that translates computer code written in one programming language (the source
language) into another language (the target language). The name "compiler" is primarily used for programs that
translate source code from a high-level programming language .
Keywords in C
As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all
keywords allowed in ANSI C.
Example of keyword-
Int - Keyword
Money - Variable of type int (integer)
C Identifiers
● To indicate the storage area, each variable should be given a unique name (identifier).
● Variable names are just the symbolic representation of a memory location.
● Here, playerScore is a variable of int type. Here, the variable is assigned an integer value 95.
● The value of a variable can be changed, hence the name variable.
Rules for naming a Variable
● A variable name can only have letters (both uppercase and lowercase letters),
digits and underscore.
● The first letter of a variable should be either a letter or an underscore.
● There is no rule on how long a variable name (identifier) can be. However, you
may run into problems in some compilers if the variable name is longer than 31
characters.
Note : You should always try to give meaningful names to variables. For
example: firstName is a better variable name than fn.
Rules for naming a Variable
C is a strongly typed language. This means that the variable type cannot be changed
once it is declared. For example:
Here, the type of number variable is int. You cannot assign a floating-point (decimal)
value 5.5 to this variable. Also, you cannot redefine the data type of the variable to double.
By the way, to store the decimal values in C, you need to declare its type to either double
or float.
C Data types
Int
Integers are whole numbers that can have both zero, positive and
negative values but no decimal values. For example, 0, -5, 10.
Keyword char is used for declaring character type variables. For example,
void is an incomplete type. It means "nothing" or "no type". You can think of void as absent.
For example, if a function is not returning anything, its return type should be void.
If you need to use a large number, you can use a type specifier long. Here's how:
Here variables a and b can store integer values. And, c can store a floating-point number.
If you are sure, only a small integer ([−32,767, +32,767] range) will be used, you can use short.
Short and Long
You can always check the size of a variable using the sizeof() operator.
Singed and Unsigned
In C, signed and unsigned are type modifiers. You can alter the data storage of a data type by using
them: