HISTORY OF PROGRAMMING
What is C Programming?- is a general-purpose, procedural, imperative computer
programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone
Laboratories to develop the UNIX operating system.
Why to Learn C Programming?- is a MUST for students and working professionals to
become a great Software Engineer specially when they are working in Software
Development Domain.
Easy to learn *It produces efficient programs
Facts about C:
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around the early 1970s.
C Programs- can vary from 3 lines to millions of lines and it should be written into one or
more text files with extension.
The C Compiler- source code written in source file is the human readable source for
your program.
Hello World Example
* Preprocessor Commands *Functions
*Variables *Statements & Expressions
*Comments
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
Tokens in C
Semicolons- in a C program, the semicolon are a statement terminator.
Comments- helping text in your C program and they are ignored by the compiler.
Identifiers- name used to identify a variable, function, or any other user-defined item.
Starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters,
underscores, and digits (0 to 9).
Keywords- words may not be used as constants or variables or any other identifier
names.
Whitespace in C- is the term used in C to describe blanks, tabs, newline characters and
comments.
C Programming Keywords & Identifiers
Keywords- predefined, reserved words used in programming.
Ex: Int money;
Identifiers- name given to entities such as variables, functions, structures etc.
Ex: int money;
double accountBalance;
Here, money and accountBalance are identifiers.
Rules for naming identifiers
A valid identifier can have letters (both uppercase and lowercase letters), digits
and underscores.
The first letter of an identifier should be either a letter or an underscore.
Variables, Constants and Literals.
A variable is a container (storage area) to hold data.
Ex: int playerScore = 95
Here playerScore is a variable of int type
Literals
Are data used for representing fixed values.
Constants
Whose value cannot be changed.
C Programming Data Types
Data Types
Declarations for variables.
Ex: int myVar;
Int id,age
float salary;
double price;
Float normalizationFactor = 22.442e2;
The size of float (single precision float data type) is 4 bytes. And the size of double
(double precision float data type) is 8 bytes.
char test = 'h';
Void
short and long
– If you need to use large number you can use a type specifier long.
signed and unsigned
– unsigned int x;
– int y;
– x can hold only zero and positive values
Output function Printf ()
#include <stdio.h>
int main() {
int testInteger = 5;
printf("Number = %d", testInteger);
return 0;
}
Output:
Number = 5
Output function Scanf ()
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
Output:
Enter an integer: 4
Number = 4
Arithmetic Operators
American Standard Code for Information interchange, is a character encoding
standard for electronic communication.
Hierarchy Operations
Increment ++ increases the value by 1 whereas decrement decreases the value
by 1
Ex: ++a, --d
Assignment Operators
Relational Operators
Logical Operators