CP 111 — Computer Programming 1
Lesson 1: Introduction to C Language
C Language
- Is a general purpose, procedural programming language used to develop software & applications.
Note: C is nicknamed "The Start-up Basic."
Brief History of C
Early 1970s
- C was developed by Dennis Ritchie at Bell Labs.
- It was originally created to rewrite the Unix Operating System (OS).
Example operating systems built using C: Linux, Windows, iOS.
1978 — K&R C
- The first official documentation of the C language was published by Brian Kernighan and Dennis Ritchie in
the book "The C Programming Language".
Note: this book is considered the most referenced guide to the language.
1990's — ANSI C
- The American National Standards Institute (ANSI) established a standardized version of C, known as ANSI
C (or C89).
1990s — C99
- A new standard called C99 was introduced.
- Several new features were added, such as inline functions, variable-length arrays, and new data types like
long int for better precision.
2011 — C11
- The ISO (International Organization for Standardization) released the C11 standard.
2017 — C17
- The most recent standard.
- It primarily focused on bug fixes and minor improvements, maintaining the stability of the language.
Basic Program Structure of C
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
Explanation of the Basic Structure
#include <stdio.h>
- Header for input and output.
int main()
- Starting point of execution.
printf()
- Used to display/output.
return 0;
- Successful termination of the program.
Common Symbols in C
- & — ampersand — used for scanf, e.g. scanf("%d", &number);
- % — percent
- [ ] — square brackets
- { — open curly braces/brackets
- } — closing curly braces/brackets
- : — colon
- ; — semi colon
- + — add/addition
- / — forward slash
- \ — back slash
- ( ) — open & close parenthesis
- - — minus/subtract
- _ — underscore
- @ — at symbol
- " " — quotation marks
Lesson 2: Variables and Data Types in C
Variable
Is a storage location in memory with a specific name, where data can be stored and manipulated during the
execution of a program.
Declaring a Variable
Syntax:
data type variable_name;
Example:
int age;
float grade;
Initializing a Variable
Syntax:
data type variable_name = value;
Example:
int age = 14;
float grade = 75.3;
Basic Data Types
a. int (integer)
- Used to store integers (whole numbers).
b. float
- Used to store floating point numbers.
c. double
- Used to store double precision floating point numbers.
d. char
- Used to store single characters.
e. void
- Represents the absence of a value.
C Modifiers
1. Signed
- Allows a variable to store both positive & negative values.
Example:
signed int number = 100;
2. Unsigned
- Allows a variable to store positive values only.
Example:
unsigned int number = 100;
3. Short
- Reduces the storage size of an integer to 2 bytes.
Example:
short int age = 10;
4. Long
- Increases the storage size of an integer or double.
Example:
long int value = 1000100;