Professional Documents
Culture Documents
FOP Notes
FOP Notes
INTRODUCTION
1. ORIGINS AND DEVELOPMENT
• Ritchie wanted to make a language that is easy to use and can be used on
different types of computers.
• C is closely connected with the UNIX operating system. It has been the
language of choice for making a big part of the UNIX system and its apps
since the 1970s.
• One of C's strengths is that it can work on different computers. This made
UNIX one of the first portable operating systems. This means that the code
that makes up UNIX doesn't need to know or care about the specific
computer it's running on.
3. HISTORICAL CONTEXT
• C has its roots in earlier programming languages. It grew from BCPL (Basic
Combined Programming Language) and B, both made at Bell Laboratories.
• The previous version of C was called B. Ken Thompson made it for the DEC
PDP7 computer. Ritchie made it even better and that's how C came to be.
4. STANDARDIZATION
• In 1983, a group decided on a set of rules for using C. The goal was to
create a clear way of writing C that could work on any computer.
• These rules are called ANSI C, and they became the standard way to use C.
There's also another set of rules by ISO that's very similar.
• Around the late 1990s and early 2000s, people were talking about making
some new rules for C, which might be called "C9X." This shows that C is
still changing and improving.
2. LINKING SECTION
Purpose: Specify header files for linking keywords or functions used in the
program.
3. DEFINITION SECTION
Example:
int main()
{
// Declaration section
// Executable section
return 0;
}
/* Simple program in C */
#include <stdio.h>
int main()
{
printf("Welcome to C programming");
return 0;
}
/* End of main */
C TOKENS: THE SMALLEST UNITS
Tokens in C are the smallest units, comprising operators, special symbols, strings,
constants, identifiers, and keywords. Each serves a distinct purpose in the
language.
1. OPERATORS
2. SPECIAL SYMBOLS
3. STRINGS
Example: "Sivasree"
4. CONSTANTS
These are fixed values that don't change during program execution.
5. IDENTIFIERS
6. KEYWORDS
IDENTIFIERS IN C
Identifiers are names given to variables and other program elements like
functions, arrays, etc. They must adhere to specific rules:
1. Identifiers can consist of letters (A-Z, a-z), digits (0-9), and underscores (_).
Examples of Identifiers:
• userName
• totalAmount
• num1
After naming a variable, it must be declared to the compiler along with its data
type. The format for declaring variables is:
Where DataType can be float, int, char, or any other data type. variable1,
variable2, variable3, etc., are the names of the variables.
CONSTANTS IN C
Constants are values that stay the same while a program runs. There are two
main types:
1. NUMERIC CONSTANTS:
Floating Point Constants have a decimal point or 'e' (like 1e2 for a very small
number).
2. CHARACTER CONSTANTS
• These are single characters, like 'a', written between single quotes.
• Some special characters, like '\n', represent things like a new line.
Don't confuse single character like 'a' with a string like "a". They're different in C.
ESCAPE SEQUENCES:
• \a : Alert
• \b : Backspace
• \f : Form feed
• \n : New Line
• \r : Carriage return
• \t : Horizontal Tab
• \v : Vertical Tab
DATA TYPES IN C
Data types are crucial in programming as they specify how data is stored and
what operations can be performed on it. C supports four classes of data types:
Examples:
int a, b;
char c;
Derived data types are used to store a set of data values. Examples include
Arrays and Structures.
Examples:
int a[10];
char name[20];
C provides typedef for creating new data type names defined by the user. For
example, the declaration:
makes Integer a synonym of int. Now, Integer can be used in declarations, casts,
etc., like:
which will be treated by the C compiler as the declaration of num1 and num2 as
int variables. typedef is especially useful with structures and pointers.
OPERATORS IN C
Operators are symbols that instruct the compiler to perform specific
mathematical or logical operations. They are used to form expressions. C
operators can be classified into several categories:
1. ARITHMETIC OPERATORS
• + : Addition
• - : Subtraction
• * : Multiplication
• / : Division
• % : Modulo Division (Remainder)
Example:
int a = 10, b = 5;
int sum = a + b; // sum will be 15
2. RELATIONAL OPERATORS
Example:
int x = 10, y = 5;
if (x > y)
{
printf("x is greater than y");
}
else
{
printf("x is not greater than y");
}
3. LOGICAL OPERATORS
4. ASSIGNMENT OPERATORS
• = : Assignment Operator
• +=, -=, *=, /=, %= : Shorthand Assignment Operators
Example:
int x = 5;
x += 3; // Equivalent to x = x + 3, x will be 8
• ++ : Increment
• -- : Decrement
Example:
6. CONDITIONAL OPERATOR
7. BITWISE OPERATORS
Example:
int x = 5, y = 3;
int result = x & y; // Bitwise AND, result will be 1
8. SPECIAL OPERATORS
• , : Comma Operator
• sizeof : Size of Operator
• & : Address-of Operator
• * : Pointer Operator
• . : Member Selection Operator (Dot Operator)
• > : Member Selection Operator (Arrow Operator)
INPUT AND OUTPUT IN C
C uses printf for output and scanf for input. The printf statement displays the
prompt, and the scanf statement reads the input and stores it in variable.
#include <stdio.h>
int main()
{
int num;
return 0;
}
GIVE OUTPUT:
• This statement uses the printf function to print a message to the console.
In this case, it displays the message "Enter an integer: ".
GET INPUT:
scanf("%d", &num);
These two statements work together to prompt the user to enter an integer, and
then store that integer value in the variable num.