C Language

What is Language?

A programming language is a formal language used to communicate instructions to a computer. These instructions tell the computer what to do — such as perform calculations, store data, show results, or control hardware.

There are 2 types of languages, known as

  1. Low-level languages
    1. Machine/Binary Language
    2. Assembly Level Language
  2. High-level languages

What is Machine/Binary language?

Binary language is the fundamental language of computers, made up of only two digits: 0 and These digits are known as binary digits or bits. It is a machine-understandable format.

Data is stored in the form of binary, CPU processes instructions in binary, and communication between systems (network) is in the form of binary.

What is Assembly Level language?

Assembly language is a low-level programming language that is one step above machine language (binary), and is closely related to the computer’s hardware. It uses mnemonics (short English-like codes) to represent machine-level instructions.

For example:

  1. LOAD 55 1002H ; Store value 55 into 1002H memory.
  2. MOV AX, 5 ; Move the value 5 into register AX
  3. ADD AX, 2 ; Add 2 to AX
Feature Machine Language Assembly Language High-level Language
Human readable No 50% Yes
Easy to Write/Debug No 50% Yes
Speed Very fast Very fast Slow
Portability No No Yes

Applications of Assembly Language:

Assembly languages are used in the following areas…

  1. Embedded Systems
  2. Device Drivers
  3. Traffic Signaling
  4. Operating Systems
  5. System Boot Programs etc.,
C Character Set

In C language, the character set refers to the collection of valid characters that the C compiler recognizes and can use to write programs. This character set includes…

  1. Letters:
    1. Uppercase Alphabet: A-Z
    2. Lowercase Alphabet: a-z
  2. Digits: 0-9
  3. Special Symbols: ~ ! @ # % ^ & * ( ) _ – + = { } [ ] | \ : ; ” ‘ < > , . ? /
  4. White Spaces: Space, tab(\t), New line (\n), Carriage return(\r), form feed (\f), etc.,

In C language, tokens are the smallest individual units (or building blocks) of a C program that the compiler can recognize and process. When you write a C program, the compiler breaks it into tokens during the lexical analysis phase

Types of Tokens in C:

  1. Identifiers
  2. Keywords
  3. Constants
  4. Operators
  5. Strings
  6. Special Symbols

Identifiers are names given to variables, functions, arrays, etc., defined by the programmer. Rules to determine an identifier …

  1. Valid characters are letters(a-z,A-Z), digits(0-9), and an underscore character(_).
  2. It should start with a letter or an underscore.
  3. It should not start with a digit.
  4. Special characters are not allowed except an underscore.
  5. Identifiers are case sensitive.
  6. It should not be a keyword.
  7. If it is a constant, write in capitals.

A keyword is a word whose meaning is defined by the language level. And also called reserved words. In C, there are 32 keywords and all are in small case.

auto break case const continue char default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union signed void volatile while

In C, constants are fixed values that can’t be changeable during the program execution. These are two types…

  1. Numerical
    1. Integral
      1. Represents without decimal point values. And can be in 4 formats.
        1. Decimal Numbers
          1. Base value is 10
          2. The digits are 0 1 2 3 4 5 6 7 8 9
        2. Octal Numbers
          1. Base Value is 8
          2. The digits are 0 1 2 3 4 5 6 7
        3. Hexadecimal Numbers
          1. Base value is 16.
          2. The digits are 0 1 2 3 4 5 6 7 8 9 A B C D E F
        4. Binary Numbers
          1. Base value is 2
          2. The digits are 0 1
    2. Float/Real
      1. These are with decimal point values.
      2. Can be represented in two ways.
        1. General format
          1. 1.1, 123.45, -23.76,…
        2. Exponent format
          1. 12.3E5 its meaning 12.3×105;
  2. Non-Numerical
    1. These are characters like the alphabet, digits, and special characters.
    2. In DOS There are 256 characters.

An operator is a symbol that performs a task. There are 8 different types of operators. They are…

  1. Arithmetic Operators
  2. Assignment Operators
  3. Relational Operators
  4. Conditional/Ternary Operator
  5. Logical Operators
  6. Increment/Decrement Operators
  7. Bitwise Operators and 
  8. Special Operators

Arithmetic Operators:

Arithmetic Operators are used to perform basic arithmetic operations like addition, subtraction, and so on… The Operators are…

Operator Meaning Example
+ Addition 10 + 3 = 13
- Subtraction 10 - 3 = 7
* Multiplication 10 * 3 = 30
/ Division(Quotient) 10 / 3 = 3
% Modulas (Remainder) 10 % 3 = 1

Assignment Operators:

Assignment operators are used to assign a value to a variable. These operators are also called short-cut operators.

Operator Meaning Example
= Assignment a = 10 (a value is 10)
+= After addition the value is stored in the same variable. a += 5 (a value is 15)
-= After subtraction the value is stored in the same variable. 10 -= 8 (a value is 7)
*= After multiplication the value is stored in the same variable. 10 *= 3 (a value is 21)
/= After division the value is stored in the same variable. 10 /= 2 (a value is 5)
%= After division the remainder is stored in the same variable. a %= 3 (a value is 2)

Relational Operators:

Relational operators are used to compare two values/expressions. These operators return either true(1) or false(0). These operators are also referred to as comparison operators.

Operator Meaning Example
= Assignment a = 10 (a value is 10)
+= After addition the value is stored in the same variable. a += 5 (a value is 15)
-= After subtraction the value is stored in the same variable. 10 -= 8 (a value is 7)
*= After multiplication the value is stored in the same variable. 10 *= 3 (a value is 21)
/= After division the value is stored in the same variable. 10 /= 2 (a value is 5)
%= After division the remainder is stored in the same variable. a %= 3 (a value is 2)

Logical Operators:

Logical operators are used to compare more than two values or more than 1 expression. These operators return either true(1) or false(0). The truth table is…

Exp1 Exp2 Logical AND (&&) Logical OR (||)
true true true true
true false false true
false true false true
false false false false
Exp ! Exp
true false
false true

Conditional Operator:

? : is called the conditional operator. It tests the given condition; if it is true, it executes a single statement, otherwise it executes another single statement.

Syntax :

Exp1 ? Exp2 : Exp3;

Here, Exp1 is a conditional statement that returns either true(1) or false(0). If it is true, Exp2 is to be executed; otherwise Exp3 is to be executed.

Increment Decrement Operators

++ is called the increment operator, which increments the value by 1. For Example…

int a=10;
a++;
a value will be 11.

The post-increment operator (a++) increases the value of a variable by 1, but the current value is used first before the increment takes effect

Syntax:  variable++;

The pre-increment operator (++i) increases the value of a variable by 1 first, and then the new value is used in the expression.

Syntax: ++variable;

— is called the decrement operator, which decrements the value by 1. For Example…

int a=10;
a–;
a value will be 9.

The post-decrement operator (a--) decreases the value of a variable by 1, but the current value is used first before the decrement takes effect

Syntax:  variable–;

The pre-decrement operator (--a) decreases the value of a variable by 1 first, and then the new value is used in the expression.

Syntax: —variable;

Operator Example When Increment Happens Value Returned
Pre-increment ++a First increment, then use New value
Post-increment a++ First use, then increment Old value

Bitwise Operators:

Bitwise operators work at the bit level. They perform operations on the binary representation of integer values. These do not work on the floats.
Useful in low-level programming, device drivers, encryption, networking, and compression algorithms.
The operators are…
Operator Symbol Description Example
AND & Sets bit to 1 if both bits are 1 5 & 3 = 1
OR ` ` Sets bit to 1 if any one bit is 1
XOR ^ Sets bit to 1 if bits are different 5 ^ 3 = 6
NOT ~ Flips all bits (1→0, 0→1) ~5 = -6
Left Shift << Shifts bits to the left (multiplies by 2) 5 << 1 = 10
Right Shift >> Shifts bits to the right (divides by 2) 5 >> 1 = 2

Special Operators:

C provides some special operators that make programming easier and more efficient.  These operators have special purposes and are widely used in real-world C programs. The Operators are…

Operator Symbol Purpose
sizeof sizeof() Returns size of a type or variable
Comma , Evaluates multiple expressions, returns last one
Pointer *, & Access value/address of variables
Member Access ., -> Access struct members
Typecast (datatype) Convert one type to another

A string is a sequence of group of characters that should be enclosed within double quotes (” “). Every string ended with a NULL (‘\0’) character. For example…

  1. “Suresh”
  2. “12345”
  3. “11-Oct-1983”

Special symbols used for structure and separation in C.

  1. { } – to write a block of code.
  2. ( ) – to define a function or function call.
  3. [ ] – Array creation and indexing.
  4. ; – Statement terminator.
  5. # – Pre-processor directive

C is a structured programming language. Every C program compilation starts at a specific point and ends at a specific point. The simple C program structure is as follows…

void main()
{
  C Statements;
}

If you define the C programming structure broadly, there are 3 parts

PART-1:
Documentation Section
Link Section
Constant/Macro Section
Function Declaration Section
Global Variable Declaration Section
PART-2
void main()
{
Local Variable Declaration;
C Statements;
}
PART-3:
user-defined function()
{
Local Variables Declaration;
C Statements;
}
What is documentation Section?

In C language the Documentation Section is the first part of a C program that contains written descriptions or comments about the program. It is not executed by the compiler ; it is meant for programmers to understand the code better.

The documentation section is used for the following reasons.
1. To write the heading of the program like title, author, created date, and so on...
2. To write description of the statement.
3. To hide statements from the compilation
To write documentation use the following symbols /* and */
For Example
/* Program to find addition of two nubers */
/* This program is
develoing by suresh */

In C language, the Link Section is the part of a C program where header files and libraries are linked so that the program can use predefined functions and macros.

The Link Section contains statements that link your program with:

  • Library functions (like printf, scanf, sqrt, etc.)

  • Macros and constants defined in header files

This is done using the #include preprocessor directive.

#include <header_file_name> -- Searches in the system library directories.
#include "header_file_name" -- Searches in the current directory first, then in system directories.

The Constant or Macro Section is the part of a C program where constants and macros are defined before the program starts executing. It is usually written after the Link Section and before the main() function.

This is done using:

  • #define preprocessor directive → for macros and symbolic constants

  • const keyword → for constant variables.

To define values that will not change during program execution. 
To make programs easier to modify (change value in one place only).
To improve readability by giving meaningful names to fixed values.
Syntax:
#define MACRO_NAME value
const data_type variable_name = value;
Example:
#define PI 3.1416 // Macro constant
#define SQUARE(x) (x*x) // Macro function
const int MAX = 100; // Constant variable


The Function Declaration Section in C is where user-defined functions are declared before they are used in the program. It specifies the function name, return type, and parameters.

Syntax:

return_type function_name(parameter_list);

A global variable is a variable that is declared outside all functions (usually at the top of the program) and is accessible by all functions in the program.  Declared outside main() and any other function.

Syntax:

data_type variable_name = value;

A local variable is a variable that is declared inside a function or block and is accessible only within that function or block.

Syntax:

[storage-class] data_type variable_name = value;

Data types in C specify the type of data a variable can store and determine the amount of memory it occupies. C has 4 different types of data types:

  1. Primary/Basic Datatypes
  2. Derived/Inherited Datatypes
  3. User-defined Datatypes
  4. Empty Datatype
  5. Enumeration Datatypes
Primary/Basic Datatypes:
Used to store simple values like numbers and characters. And these are 3 types known as Integers,
Floats, and Characters.
Integers:
It represents without decimal point values, may be positive or negative numbers.These are classified as
follows...
Memory Format Specifier Min Max
short 2 bytes %d -32,768 +32,767
signed
long 4 bytess %ld -2,14,74,83,648 +2,14,74,83,647
int
short 2 bytes %u 0 65,535
unsigned
long 4 bytes %lu 0 4,29,59,67,295
Float/Real:
These are with decimal point values, and can be represented in two ways
1. General Format (2.3, -123.77, ...)
2. Exponent Format (2.3E3, 34.5E-3, ...)

Here’s the range of float, double, and long double in C (based on the IEEE 754 standard). Actual values can vary
slightly depending on the compiler and system.
The actual size and range may differ between compilers (e.g., GCC vs Turbo C).
Use <float.h> to get exact ranges on your system.
Datatype Memory Format Specifier Min.Value Max.Value
float 4 bytes %f 1.2 x 10-38 3.4 x 10+38
float double 8 bytes %lf 2.3 x 10-308 1.7 x 10+308
long double 10 bytes %Lf 3.4 x 10-4932 1.1 x 10+4932

character type:

The char data type in C is used to store single characters. Characters are stored as integer values according to the ASCII code.

Memory Min. Value Max. Value
signed %c -128 +127
char
unsigned %c 0 255

Sequential programming is the process of executing all statements one by one.

Basic IO Statements.

I/O statements in C are commands that allow a program to take input from the user (Input) and display output to the user (Output).  They are provided through the Standard Input/Output Library <stdio.h>.

Output Statements are used to display text/values on the screen. There are two types of output statements.

  1. Formated Output and
    1. printf()
      1. Syntax: printf(“text”);
  2. Unformated Output
    1. putchar()
      1. Prints a single character
      2. Syntax:
        1. putchar(‘S’);
    2. puts()
      1. Prints a string on the screen.
      2. Syntax:
        1. puts(“Hi, Suresh”);

Input statements are used to read data from standard input device known as keyboard. There are two types.

  1. Formated Input Statements and
    1. scanf()
    2. syntax:
      1. scanf(“format Specifier”, address of variable);
  2. Unformated Input Statements.
    1. getchar()
      1. Reads a single character.
      2. Syntax::
        1. char getchar( );
    2. getche()
      1. Reads a single character only.
      2. Syntax:
        1. char getche( );
    3. getch()
      1. Reads a single character but it doesn’t echo the character on to the screen.
      2. Syntax:
        1. char getch( );
    4. gets()
      1. Reads a string from the keyboard.
      2. Syntax:
        1. char* gets(variable);

To compile a C program in turbo C, you should remember the following key shortcuts.

to compile Alt + F9 or Alt + C, Enter key
to run Ctrl + F9 or Alt + R, Enter key.
to see output Alt + F5
Write a program to print a statement 'Hello world!'
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("Hello World!");
}
Output:
Hello World!
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("Suresh CH\n");
printf("Nellore\n");
printf("Andhra Pradesh");
}
Output:
Suresh CH
Nellore
Andhra Pradesh
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
printf("Enter a number : ");
scanf("%d",&n);
printf("You Entered value is : %d",n);
}

Output:
Enter a number : 123
You Entered value is : 123
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,sum;
printf("Enter value1 : ");
scanf("%d",&n);
printf("Enter value2 : ");
scanf("%d",&b);
sum = a + b;
printf("Addition : %d",sum);
}
Output:
Enter value1 : 10
Enter value2 : 20
Addition : 30

#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,sum,sub,mul,div,rem;
clrscr();
printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
sum = a + b;
sub = a - b;
mul = a * b;
div = a / b;
rem = a % b;
printf("\n %d + %d = %d",a,b,sum);
printf("\n %d - %d = %d",a,b,sub);
printf("\n %d * %d = %d",a,b,mul);
printf("\n %d / %d = %d",a,b,div);
printf("\n %d %% %d = %d",a,b,rem);
getch();
}
Output:
Enter two numbers : 10 3
10 + 3 = 13
10 - 3 = 7
10 * 3 = 30
10 / 3 = 3
10 % 3 = 1
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,temp;
printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
printf("\n Before swapping...\n a : %d \t b : %d",a,b);
temp = a;
a = b;
b = temp;
printf("\n After swapping...\n a : %d \t b : %d",a,b);
}
Output:
Enter two numbers : 10 20
Before swapping...
a : 10       b : 20
After swapping...
a : 20      b : 10
#include <stdio.h>
#include <conio.h>
void main()
{
int stid, tel, eng, mat, tot;
float avg;
char stna[20];
clrscr();
printf("Enter student id, name, and 3 subjects marks : ");
scanf("%d%s%d%d%d",&stid, stna, &tel, &eng, &mat);

tot = tel + eng + mat;
avg = (float)tot/3

printf("\n Number : %d",stid);
printf("\n Name : %s",stna);
printf("\n Telugu : %d",tel);
printf("\n English : %d",eng);
printf("\n Maths : %d",mat);
printf("\n Total : %d",tot);
printf("\n Average : %.2f",avg);
getch();
}
Output:
Enter student id, name, and 3 subjects marks :
Number :
Name :
Telugu :
English :
Maths :
Total :
Average :

 

#include <stdio.h>

int main()
{
int empid;
char ename[20];
float sal, hra, da, gsal, itax, pf, nsal;

printf(“Enter Employee id, name, and basic salary : “);
scanf(“%d%s%f”,&empid, &ename, &sal);

hra = sal * 20/100;
da = sal * 55/100;
gsal = sal + hra + da;
itax = gsal * 5/100;
pf = gsal * 8/100;
nsal = gsal – (itax + pf);

printf(“\n ID : %d”,empid);
printf(“\n Name : %s”,ename);
printf(“\n Basic : %.2f”,sal);
printf(“\n H.R.A. : %.2f”,hra);
printf(“\n D.A. : %.2f”,da);
printf(“\n Gross : %.2f”,gsal);
printf(“\n Incometax : %.2f”,itax);
printf(“\n Prodidend Fund : %.2f”,pf);
printf(“\n Net : %.2f”,nsal);

return 0;
}

Output:

Enter Employee id, name, and basic salary : 1001 Suresh 5600

ID : 1001
Name : Suresh
Basic : 5600.00
H.R.A. : 1120.00
D.A. : 3080.00
Gross : 9800.00
Incometax : 490.00
Prodidend Fund : 784.00
Net : 8526.00

What is conditional Programming?

Conditional programming in C language refers to the ability to make decisions during program execution based on specific conditions or expressions. It allows the program to execute different code blocks depending on whether a given condition evaluates to true (non-zero) or false (zero).

This is a fundamental concept in programming, enabling the implementation of decision-making logic.

To make decisions there are 3 different ways.

  1. Conditional Operators
  2. If Statement
  3. Switch Statement.

The conditional operator in C language is a ternary operator (?:) that allows you to make decisions in a single line. It is the only ternary operator in C because it requires three operands:
Syntax:
     condition ? expression_if_true : expression_if_false;
In the above syntax, condition is a boolean expression (evaluates to true or false). expression1 is to be executed if the condition is true (non-zero). expression2 is to be executed if the condition is false (zero).

Relational Operators:

In C, relational/comparison operators are used to compare two values and return either true(1) or false(0).
In C, true=1, false=0.
Any non-zero value is true.
The relational/comparison operators are…

Operator Expression Return Value
== (is equal to) 10==20 0
!= (is not equal to) 10 != 20 1
< (Less than) 10 < 20 1
<= (Less than or equal to) 10 <= 5 0
> (Greaer than) 10 > 20 0
>= (Greater than or equal to) 10 >= 10 1

Logical Operators:

The logical operators are used to compare more than two values or to combine more than 1 relational operators.
These operators return either true(1) or false(0).
The logical operators are...
Operator Expression Return Value
&& (Logical AND) (10>5 && 20>10) 1
|| (Logical OR) (10<5 || 10>20) 0
! (Logical NOT) ! (10<20 || 10>20) 0
WAP to demonstrate Conditional Operator.
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf("Enter any number : ");
scanf("%d",&n);
(n>0) ? printf("+ve Number") : printf("-ve Number");
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf("Enter any number : ");
scanf("%d",&n);
(n%2==0) ? printf("Even Number") : printf("Odd Number");
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a and b values : ");
scanf("%d%d",&a,&b);
(a>b) ? printf("a is biggest") : printf("b is biggest");
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,big;
clrscr();
printf("Enter a ,b , and c values : ");
scanf("%d%d%d",&a,&b,&c);
big = (a>b && a>c) ? a : (b>c) ? b : c;
printf("Biggest Number is : %d",big);
getch();
}
What is if statement ?

The if statement in C language is a conditional control statement that allows a program to execute a block of code only if a given condition is true. If the condition is false, the code inside the if block is skipped.

The if statement is divided into 4 forms, known as

  1. Simple If
  2. If Else 
  3. Else If Ladder
  4. Nested If

A simple if statement in C language is the basic form of decision-making, where a block of code is executed only if a specified condition is true. If the condition is false, the program simply skips that block without executing it.

Syntax:

if (condition) {
      Code to be executed if the condition is true
}

In the above syntax

  • The ifis a keyword, used for decision-making.

  • If the condition is true, the code block executes.

  • If the condition is false, the program skips the block.

WAP to print an absolute value of a given number.
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf("Enter a number : ");
scanf("%d",&n);
if( n < 0 )
{
n = -n;
}
printf("Absolute value is : %d",);
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter a and b values : ");
scanf("%d%d",&a,&b);
if( a > b )
{
printf("a is big");
}
if( b > a )
{
printf("b is big");
}
printf("Absolute value is : %d",);
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter a,b, and c values : ");
scanf("%d%d%d",&a, &b, &c);
if( a>b && a>c)
printf("a is big");
if( b>a && b>c)
printf("b is big");
if( c>a && c>b)
printf("c is big");

getch();
}

The if-else statement in C is a control structure that allows for conditional execution of code blocks. It provides a way to execute one block of code if a specified condition evaluates to true and another block of code if the condition evaluates to false.

Syntax:

if (condition) {
     Block of code to be executed if condition is true
} else {
     Block of code to be executed if condition is false
}

In the above syntax…

  1. ‘condition’ is a logical expression that evaluates to either true or false.
  2. If ‘condition’ evaluates to true, the block of code enclosed within the first set of curly braces {} is executed.
  3. If ‘condition’ evaluates to false, the block of code enclosed within the second set of curly braces {} (after the else keyword) is executed.
WAP to find biggest of two numbers

#include <stdio.h>
int main() {
int a,b;
printf(“Enter two numbers : “);
scanf(“%d%d”,&a,&b);
if(a>b) {
printf(“a is big”);
}
else {
printf(“b is big”);
}
return 0;
}

Output:

Enter two numbers : 10 20
b is big
Enter two numbers : 20 10
a is big

#include <stdio.h>
int main()
{
   int n;
   printf(“Enter n : “);
   scanf(“%d”,&n);
   if( n>0)
      printf(“+ve number”);
   else
      printf(“-ve number”);
   return 0;
}

Output:
Enter n : 12
+ve number
Enter n : -32
-ve numbe

#include <stdio.h>
int main()
{
     int age;
     printf(“Enter person age :”);
     scanf(“%d”,&age);
     if(age>18)
          printf(“Elligible to vote”);
     else
          printf(“Not Elligible to vote”);
     return 0;
}

Output:
Enter person age :45
Elligible to vote
Enter person age :16
Not Elligible to vote

The “else if ladder” in C is a control structure that allows for multiple conditional branches to be evaluated in sequence. It provides a way to handle scenarios where there are more than two possible outcomes based on different conditions.

Syntax:
if (condition1) {
     Block of code to be executed if condition1 is true
} else if (condition2) {
     Block of code to be executed if condition2 is true
} else if (condition3) {
     Block of code to be executed if condition3 is true
}
else {
     Block of code to be executed if none of the conditions are true
}

The execution process is as follows…

  1. Each if statement is followed by an else if statement, except for the last else statement, which is optional.
  2. Conditions are evaluated in sequence from top to bottom. If the condition in an if or else if statement evaluates to true, the corresponding block of code is executed, and the rest of the ladder is skipped. 
  3. If none of the conditions in the ladder evaluate to true, the block of code associated with the else statement (if present) is executed
WAP to find biggest of three numbers

#include <stdio.h>
int main()
{
     int i,j,k;
     printf(“Enter 3 numbers : “);
     scanf(“%d%d%d”,&i,&j,&k);
     if( i>j && i>k)
          printf(“First number is big”);
     else if(j>k)
          printf(“Second number is big”);
     else
          printf(“Third number is big”);
     return 0;
}

Output:
Enter 3 numbers : 10 20 30
Third number is big
Enter 3 numbers : 30 20 10
First number is big
Enter 3 numbers : 20 30 10
Second number is big

#include <stdio.h>
int main()
{
     int wd;
     printf(“Enter week day code : “);
     scanf(“%d”,&wd);
     if( wd==1)
          printf(“Sunday”);
     else if(wd==2)
          printf(“Monday”);
     else if (wd==3)
          printf(“Tuesday”);
     else if(wd==4)
          printf(“Wednesday”);
     else if(wd==5)
          printf(“Thursday”);
     else if(wd==6)
          printf(“Friday”);
     else if(wd==7)
          printf(“Saturday”);
     else
         printf(“Invalid week day code “);
     return 0;
}

Output:
Enter week day code : 4
Wednesday
Enter week day code : 6
Friday
Enter week day code : 10
Invalid week day code

A nested if statement in C refers to an if statement that is embedded within another if statement. This technique allows for the execution of conditional code blocks based on multiple levels of conditions.

Syntax:

if (condition1) {
     Outer if block
     if (condition2) {
          Nested if block
          Code to be executed if both condition1 and condition2 are true
     }
     Additional code outside of the nested if block
}
Additional code outside of the outer if block

In the above syntax:

  1. The outer if statement contains another if statement (the nested if statement) within its block of code.
  2. The nested if statement is only executed if the condition of the outer if statement evaluates to true.
  3. Conditions are evaluated sequentially, and the nested if statement is only executed if both the condition of the outer if statement and the condition of the nested if statement evaluate to true.
WAP to find smallest of 3 numbers

#include <stdio.h>
int main()  {
     int a,b,c,small;
     printf(“Enter 3 numbers :”);
     scanf(“%d%d%d”,&a,&b,&c);
     if(a<b) {
          if(a<c)
              small=a;
         else 
              small=c;
     }
     else {
          if(b<c)
              small=b;
         else
              small=c;
     }
     printf(“Smallest Value : %d”,small);
     return 0;
}

Output:
Enter 3 numbers :10 20 30
Smallest Value : 10
Enter 3 numbers :20 10 30
Smallest Value : 10
Enter 3 numbers :30 20 10
Smallest Value : 10
What is iterative or looping ?
Introduction to Arrays.

An array in C, is a secondary datatype element, that is used to store more than one value in a single variable.  It allocates sequence memory blocks to store values. 

Introduction to Functions
ctype.h library

The ctype.h header declares a set of functions that are used for testing and mapping characters.  Makes character-checking code much more readable and intentional

These functions check if a character c belongs to a certain category. They return a non-zero (true) integer if the condition is true, and 0 (false) if it is false.

Function Prototype Description Equivalent To (in ASCII)
int isalnum(int c); Checks if c is an alphanumeric character (a letter or a digit). isalpha(c) || isdigit(c)
int isalpha(int c); Checks if c is an alphabetic letter (uppercase or lowercase). isupper(c) || islower(c)
int iscntrl(int c); Checks if c is a control character. (e.g., 0x00 (NUL) to 0x1F (US), and 0x7F (DEL)) (c >= 0 && c <= 31) || c == 127
int isdigit(int c); Checks if c is a decimal digit (0 to 9). c >= '0' && c <= '9'
int isgraph(int c); Checks if c has a graphical representation (any printing character except space). isprint(c) && c != ' '
int islower(int c); Checks if c is a lowercase letter (a to z). c >= 'a' && c <= 'z'
int isprint(int c); Checks if c is a printing character (includes space ' '). c >= 0x20 && c <= 0x7E (space to tilde)
int ispunct(int c); Checks if c is a punctuation character (printing character that is not alphanumeric or space). isprint(c) && !isalnum(c) && c != ' '
int isspace(int c); Checks if c is a white-space character. (e.g., space ' ', form feed '\f', newline '\n', carriage return '\r', horizontal tab '\t', vertical tab '\v'). (c == ' ') || (c >= '\t' && c <= '\r')
int isupper(int c); Checks if c is an uppercase letter (A to Z). c >= 'A' && c <= 'Z'
int isxdigit(int c); Checks if c is a hexadecimal digit (09, af, AF). isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')
Variables & Memory Addresses: