Lab 2
Lab 2
Reading Assignments
History of C Language
Features of C Language
How to install C
First C Program
Frist C program
C program of components
► Header Files ► Additional Information
► Main Function ► Preprocessor Directives:
► Variable Declarations ► Data Types:
► Statements and Expressions ► Control Structures:
► Comments ► Error Handling:
► Functions ► Modularization:
► Return Statement ► Etc.
► Standard I/O
C program of components (cont’d)
1. Header Files
► #include directives
► provide function prototypes and definitions that
allow the C compiler to understand the functions
used in the program..
2. Main Function
► Every C program starts with the main function.
► Program's entry point, and execution starts from
here.
► Has a return type of int, indicating that it should
return an integer value to the OS upon completion.
C program of components (cont’d)
3. Variable Declarations
► Before using any variables, you should declare them with
their data types.
► This section is typically placed after the main function's curly
opening brace
4. Statements and Expressions
► This section contains the actual instructions and logic of the
program
5. Comments
► Provide human-readable explanations within the code.
► Denoted by // for single-line comments
► /* */ for multi-line comments
C program of components (cont’d)
6. Functions
►C programs can include user-defined functions
and blocks of code that perform specific tasks.
►Functions help modularize the code and make it more
organized and manageable.
7. Return Statement
►Use the return statement to terminate a function
►A return statement with a value of 0 typically
indicates a successful execution in the main function
►non-zero value indicates an error or unexpected
termination.
C program of components (cont’d)
8. Functions
►C has library functions for reading user input
(scanf) and printing output to the console (printf).
►These functions are found in C programs and are
part of the standard I/O library (stdio.h header
file).
printf() and scanf()
► The printf() and scanf() functions are used for input and
output in C language.
► Both functions are inbuilt library functions, defined in
stdio.h
A. printf(): used for output
► It prints the given statement to the console.
Syntax: printf("format string",argument_list);
2.global variable
3.static variable
4.automatic variable
5.external variable
Types of Variables in C (cont’d)
1. Local Variable
► A variable that is declared inside the function
2. Global Variable
► A variable that is declared outside the function or block
3. Static Variable
► A variable that is declared with the static keyword
Example
► static variable will print the incremented value in each function call.
Types of Variables in C (cont’d)
► Automatic Variable
► All variables in C that are declared inside the block, are
keyword.
►Syntax: extern int x=10;//external variable
Data Types in C
► A data type specifies the type of data that a variable can
store such as integer, floating, character, etc.
► There are the following data types in C language
Example :
Data Types in C : Structures
► The structure tag is optional
► Each member definition is a normal variable definition,
structure type.
Example:
Data Types in C: Structures as Function Arguments
union type.
Reading Assignment
Keywords in C