0% found this document useful (0 votes)
50 views16 pages

C Programming Basics and Structure

The document provides an overview of C programming, emphasizing its structured nature and function-oriented design. It outlines the general structure of a C program, including documentation, pre-processing statements, global declarations, the main method, and user-defined methods. Additionally, it discusses rules for writing C programs, memory management, and key concepts like source code, object code, and the linker.

Uploaded by

demo630333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views16 pages

C Programming Basics and Structure

The document provides an overview of C programming, emphasizing its structured nature and function-oriented design. It outlines the general structure of a C program, including documentation, pre-processing statements, global declarations, the main method, and user-defined methods. Additionally, it discusses rules for writing C programs, memory management, and key concepts like source code, object code, and the linker.

Uploaded by

demo630333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAMMING IN C

Mrs. Shruti Tavaragundi


Assistant Professor,
Dept. of CSE, JSSATE,
Bengaluru - 60.
Basics of C Programming?

C is a structured programming language. So every


instruction in a c program must follow the
predefined structure (Syntax).

C is also known as Function Oriented Programming


Language. So every executable statement must
written inside a function.
General Structure of a C Program
/* Documentation */
Pre-Processing Statements

Global Declarations

Main method

Used defined methods implementation


General Structure of a C Program

Documentation /* Documentation */
Pre-Processing
- It is used to provide brief information Statements
of the program. Global Declarations

- This part is written using comments. Main method

- Generally the documentation part does Used defined methods


not executed by compiler & it is implementation
optional part.
General Structure of a C Program
Pre-Processing Statements
- It is used to link the header files, /* Documentation */
Pre-Processing
define the constants, etc... Statements
Global Declarations
- Every preprocessor statement starts
with hash (#) symbol. Main method

- Every Preprocessor statement tells to Used defined methods


the compiler to perform required implementation

pre-processing before the actual


compilation.
General Structure of a C Program
Pre-Processing Statements
- Examples /* Documentation */
Pre-Processing
#include Statements
#define Global Declarations
#undef
#ifdef
#ifndef Main method
#if
#else Used defined methods
#elif implementation
#endif
#error
#pragma
General Structure of a C Program
Global Declaration
- This part is used to declare the /* Documentation */
Pre-Processing
variables which are common for multiple Statements
methods. Global Declarations

- In this section, we also declare Main method


enumeration, structure, unions,
userdefined methods etc... Used defined methods
implementation

- It is also optional part. According to


our requirement we write this section.
General Structure of a C Program
Main method
- main method is the compulsory part for any c /* Documentation */
program. Pre-Processing
Statements
- C language is a function oriented programming Global Declarations
language, so every c program must have at least
one function and that must be main. Main method
- Main is a userdefined method which specifies
the starting point of the program execution. Used defined methods
implementation
- Every c program execution starts with main
method and ends with main method itself.
General Structure of a C Program
Userdefined Methods
- In this section of the program we write the /* Documentation */
actual code for the userdefined methods. Pre-Processing
Statements
- Userdefined methods can be implemented Global Declarations
either before or after the method.
- If it is implemented after the main then it must Main method
be declared either inside or before the main
method. Used defined methods
implementation
- If it is implemented before the main then the
declaration can be ignored.
General Structure of a C Program - Example
/* Program to print a message Hello World! */
#include<stdio.h>

void main()
{

printf(“Hello World!!!!”);

}
Rules for Writing C programs
• Every c program must contain exact one main
method
• Every executable instruction must end with
semicolon (;)
• All the system defined words (Keywords) must
be used in lowercase letters
• Every open brace ({) must have the respective
closing brace (})
• The variables must be declared in the
declaration section before they are used
C's Memory Map
• A compiled C program creates and uses four logically distinct
regions of memory.
• The first region is the memory that actually holds the
program's executable code.
• The next region is memory where global variables are stored.
• The remaining two regions are the stack and the heap.
• The stack is used for a great many things while your program
executes. It holds the return addresses of function calls,
arguments to functions, and local variables. It will also save
the current state of the CPU.
The heap is a region of free memory that your program can
use via C's dynamic memory allocation functions. Although
the exact physical layout of each of the four regions of
memory differs among CPU types and C implementations,
the diagram in Figure 1-2 shows conceptually how your C
programs appear in memory.
NOTE
• Source code The text of a program that a user can read,
commonly thought of as the program. The
source code is input into the C compiler.
• Object code Translation of the source code of a program into
machine code, which the computer
can read and execute directly. Object code is the input to the linker.
• Linker A program that links separately compiled modules into
one program. It also combines the
functions in the Standard C library with the code that you wrote.
The output of the linker is an
executable program.
Library The file containing the standard functions that your
program can use. These functions
include all I/O operations as well as other useful routines.
• Compile time The time during which your program is being
compiled.
• Run time The time during which your program is executing.

NOTE
To the five basic data types defined by C89 , C99 adds three
more: _Bool, _Complex, and _Imaginary.

You might also like