C Programming Data Types, Storage Classes, and Input Output Functions
C Data Types and Classification
Data types indicate the specific type of data that a variable can hold in memory, which can be numeric or non-numeric in nature.
The basic, built-in, primary, or fundamental data types in C are:
intfloatdoublecharvoid

Data types in C are broadly categorized into three distinct groups:
Built-in Datatypes:
int,float,char,double,voidDerived Datatypes:
Array,functionsUser-Defined Datatypes:
Enum,Struct,union

Overview of basic data types, keywords, and memory allocations:
Integer: Keyword
int, Memory size:Real (floating-point): Keyword
float, Memory size:Double precision: Keyword
double, Memory size:Character: Keyword
char, Memory size:Non-specific: Keyword
void, Memory size:--

Detailed Characteristics of Basic Data Types
Integer (
int) Data Type:Keyword used to represent standard whole numbers without decimal components.
An integer is defined as a sequence of digits without a decimal point.
The numeric range of an integer depends on the word length of the computer system.
Word length refers to the number of bits that can be accessed simultaneously by the processor.
Standard allocation: () of memory.
Declaration example:
int num;Valid Examples:
-248,14042,27246,0,+1996Invalid Examples:
3,333(contains illegal comma),-34.0(contains decimal point),+3,468.3(contains comma and decimal point),99999999(exceeds standard 16-bit integer boundary)

Floating-Point (
float) Data Type:Keyword used to indicate real numbers containing fractional components.
Provides precision up to
Standard allocation: () of memory.
Declaration example:
float num;Basic examples:
23.05,56.5,32Valid Examples:
-248.45,1.4042 E + 02,27246,0Invalid Examples:
3,333(contains comma),-34.0(listed as invalid integer),+3,468.3(contains comma),99999999

Character (
char) Data Type:Keyword used to specify individual character values.
Standard allocation: () of memory.
Character constants must be enclosed within a pair of single quotes (apostrophes).
Valid character examples:
'a','m','$','%','1','5'Declaration and assignment example:
char gender; gender=\'M\';String Constant: A sequence of characters enclosed within a pair of double quotes, automatically terminated by a null character (
'\0'). Examples include"Program"and"2k8".
Double Precision (
double) Data Type:Keyword used to denote double-precision floating-point numbers.
Standard allocation: () of memory.
Precision directly correlates with data accuracy: while
floatstores up to after the decimal point,doublestores up to after the decimal point.Value example:
123.00000000000000000Declaration example:
double num;
Void (
void) Data Type:Represents a non-specific or empty type that stores nothing.
Expressly informs the compiler that no value is to be returned or expected.
Memory Sizes and Ranges of Data Types
Detailed memory allocation and minimal ranges across standard data types and modifiers:
char: Size: , Minimal Range:unsigned/unsigned char: Size: , Minimal Range:signed char: Size: , Minimal Range:int: Size: , Minimal Range:unsigned int: Size: , Minimal Range:signed int: Size: , Minimal Range: (Same asint)short int: Size: , Minimal Range: Same asintunsigned short int: Size: , Minimal Range:signed short int: Size: , Minimal Range: Same asshort intlong int: Size: , Minimal Range:signed long int: Size: , Minimal Range:unsigned long int: Size: , Minimal Range:float: Size: , Precision:double: Size: , Precision:long double: Size: , Precision: 18\text{ to }21\text{ decimal digits on most compilers
Backslash Constants and Escape Sequences
Backslash character constants (escape sequences) are special character combinations used primarily within output functions.
Although written as two characters starting with a backslash (
\), they are interpreted as a single character entity.Summary of backslash constants and their functions:
'\a': Audible Alert (Bell)'\b': Backspace'\f': Form feed'\n': New Line'\r': Carriage Return'\t': Horizontal tab'\v': Vertical Tab'\'': Single Quote'\"': Double Quote'\?': Question Mark'\\': Back Slash'\0': Null

Data Type Modifiers, Qualifiers, and Constant Declarations
Data Type Modifiers / Qualifiers:
Modifiers are keywords used to alter the storage size or signedness behavior of standard primitive data types.
The primary modifiers in C are
signed,unsigned,short, andlong.signed:Applied predominantly to integer and character types. Default integer declarations assume signed values.
For signed character types, values range from to .
unsigned:Applied to
intandchar, as well as in combination withlongorshort.Restricts values to non-negative integers; for character variables, unsigned values range from to .
long:Applied to
intanddoubledata types.Doubles the bit-length of the underlying storage (e.g., transforming a 16-bit
intinto a 32-bitlong int).short:Reduces or constrains the storage requirement of an integer type.
Declaring Variables as Constant (
const):Ensures that a variable's assigned value remains fixed throughout the entire execution of the program.
Established by prepending the variable declaration with the
constqualifier during initialization.Example:
const int class_size = 69;
Declaring Variables as Volatile (
volatile):Applied to variables whose values can be altered externally at any point without direct action from code execution.
Signals to the compiler that the variable's value must always be re-read from memory directly because it may change unexpectedly.
Example:
volatile int num=125;
Symbolic Constants (
#define):Symbolic constants are established via preprocessor directives and replace declared symbolic names with fixed constant values throughout the program prior to compilation.
Preprocessor statements begin with
#and must not end with a semicolon.Syntax format:
#define symbolic_name value_of_constantValid Preprocessor Examples:
#define X 25#define PASS_MARK 50#define PI 3.14159#define NAME "NTTF"Invalid Preprocessor Examples:
#define X=25(illegal use of assignment operator=)# define X 25(illegal whitespace between#anddefine)#define X 25;(illegal trailing semicolon;)#define X 25,Y 35(illegal comma separator for multiple assignments)#Define X 25(illegal capitalization of keywordDefine)#define $ 25(illegal character$used as identifier)

Delimiters (Separators):
Symbols that delimit boundaries between syntactic elements within a C program.
Function to separate constants, variables, expressions, and statements.
Frequently used delimiters include: Comma (
,), Semicolon (;), Blankspace, Single quote ('), Double quote (").
Storage Classes in C
A variable's storage class defines four fundamental properties:
Storage Location: The physical region of memory where the variable resides.
Initial Value: The default value assigned prior to explicit initialization.
Scope: The visibility and accessibility region of the variable within the source code.
Life (Lifetime): The duration over which the variable retains allocated memory during program run-time.
The Four Storage Classes:
Automatic (
auto):Default storage class for all local variables declared inside functions or code blocks.
Storage Place: RAM (Stack)
Initial Value: Garbage value
Scope: Local within the block
{ }where declaredLife: Created upon block execution entry; destroyed upon block execution exit
Static (
static):Used to preserve variable state across repeated block or function invocations.
Storage Place: RAM (Data segment / Heap)
Initial Value: Zero ()
Scope: Local within the declared block
Life: Retained continuously until the end of program execution
Special Property: Retains its last modified value even after exiting its block/function scope
Register (
register):Requests local storage within CPU registers for ultra-fast access speed.
Storage Place: CPU Register (internal CPU memory, not RAM)
Initial Value: Garbage value
Scope: Local within the declared block
{ }Life: Active until execution exits the containing block
External (
extern):References global variables declared outside the current block or in separate source files.
Storage Place: RAM (Data segment)
Initial Value: Zero ()
Scope: Global across multiple files in the entire application
Life: Retained throughout the entire program lifetime
Special Property: Acts as a reference declaration only; does not allocate new memory space

Input and Output (I/O) Functions
Input and Output Concepts:
Input denotes receiving or accepting external data into a program (via keyboard, command line, or files).
Output denotes transmitting or presenting processed data (to display screen, printer, or storage files).
C standard I/O library functions are housed inside the
<stdio.h>header file (Standard Input Output Header File).
Categorization of Standard I/O Functions:
Console I/O Functions: Perform data operations strictly using the system keyboard for input and the display monitor for output.
Disk I/O Functions: Perform data transfer operations on secondary storage devices such as hard disks or floppy drives.
Port I/O Functions: Handle direct hardware data transfer operations across hardware interfaces such as printer or mouse ports.
Sub-Classification of Console I/O:
Formatted Console I/O
Unformatted (Non-Formatted) Console I/O
Formatted Console I/O Functions
Formatted I/O functions allow users to read or display data formatted according to specific conversion specifications (format specifiers).
They support all primitive and complex data types (
int,float,char, strings, etc.) and provide user-friendly layout control.printf()Function:Pre-defined output function declared in
<stdio.h>used to print formatted output to the console monitor.Syntax:
printf("format string", arg1, arg2, ...);Example Implementation:
#include <stdio.h>
int main() {
// Creating an int type variable
int a = 20;
// Printing the value of a variable
printf("%d\n", a);
// Printing a string
printf("This is a string");
return 0;
}
Execution Output:
20
This is a string
scanf()Function:Pre-defined input function declared in
<stdio.h>used to read formatted data from the keyboard.Incorporates the address-of operator
&to directly assign input values to the target variable's memory address.Syntax:
scanf("Format Specifier", &var1, &var2, ...);
sprintf()Function:Stands for "string print". Formats and writes data into a target character array (string buffer) instead of printing to the console screen.
Syntax:
sprintf(array_name, "format specifier", variable_name);Example Usage:
char note[50];
sprintf(note, "My age is %d", 21);
printf("%s", note); // Output: My age is 21
Multi-variable formatting example:
sprintf(str, "Age = %d and Marks = %.1f", age, marks);sscanf()Function:
Stands for "string scanf". Reads formatted data from an existing character array/string buffer rather than waiting for keyboard input.
Syntax:
sscanf(array_name, "format specifier", &variable_name);Example Usage:
char data[] = "Arjun 21"; // existing string text
char name[20];
int age;
sscanf(data, "%s %d", name, &age);
printf("%s is %d years old", name, age); // Output: Arjun is 21 years old
Multi-variable reading example:
sscanf(data, "%d %f", &age, &marks);
Unformatted Console I/O Functions
Unformatted I/O functions operate strictly on single character values or character arrays/strings (
char).They do not support format specifiers or custom output formatting layout controls.
getch()Function:Declared in
<conio.h>.Reads a single character input from the keyboard.
Does not display (echo) the typed character on the console screen.
Returns instantly without requiring the user to press the Enter key.
Commonly utilized to hold or pause the execution screen.
Syntax:
getch();Code Example:
#include <conio.h>
#include <stdio.h>
int main() {
printf("Enter any character: ");
// Reads a character but does not display it
getch();
return 0;
}
getche()Function:Declared in
<conio.h>.Reads a single character from the keyboard and immediately displays (echoes) the character on the console screen.
Returns immediately without waiting for an Enter key press.
Syntax:
getche();Code Example:
#include <conio.h>
#include <stdio.h>
int main() {
printf("Enter any character: ");
// Reads a character and displays it immediately
getche();
return 0;
}
getchar()Function:Declared in
<stdio.h>.Reads only the first single character from the input buffer, regardless of how many characters were typed.
Waits for and requires the Enter key to be pressed before proceeding.
Syntax:
ch = getchar();Code Example:
#include <stdio.h>
int main() {
char ch;
printf("Enter any character: ");
ch = getchar();
printf("You entered: %c\n", ch);
return 0;
}
putchar()Function:Declared in
<stdio.h>.Outputs a single character at a time to the console display by accepting a direct character constant or character variable argument.
Syntax:
putchar(variable_name);Code Example:
#include <conio.h>
#include <stdio.h>
int main() {
char ch;
printf("Enter any character: ");
ch = getchar();
putchar(ch);
return 0;
}
putch()Function:Declared in
<conio.h>.Displays a single specified character at the current active cursor location on the console screen.
Syntax:
putch(variable_name);Code Example:
#include <conio.h>
#include <stdio.h>
int main() {
char ch;
printf("Enter any character:\n ");
ch = getch();
printf("\nEntered character is: ");
putch(ch);
return 0;
}
Additional string-based unformatted I/O functions include
gets()(for reading character arrays/strings) andputs()(for writing character arrays/strings).
Formatted vs. Unformatted I/O Functions
Comparative analysis of Formatted and Unformatted Console I/O Functions:
Formatting Flexibility:
Formatted I/O: Allows users to input or display data in custom formats.
Unformatted I/O: Does not allow custom user-defined formatting.
Format Specifier Support:
Formatted I/O: Fully supports format specifiers (e.g.,
%d,%f,%c,%s).Unformatted I/O: Does not support format specifiers.
User Friendliness:
Formatted I/O: Highly user-friendly for structured data presentation.
Unformatted I/O: Less user-friendly for complex data.
Supported Data Types:
Formatted I/O: Compatible with all basic and derived data types (
int,float,char,double, etc.).Unformatted I/O: Restricted exclusively to
charand string data types.Representative Functions:
Formatted I/O:
printf(),scanf(),sprintf(),sscanf()Unformatted I/O:
getch(),getche(),getchar(),putchar(),putch(),gets(),puts()
