0% found this document useful (0 votes)
9 views

Lect 3 Programming Logic Using ‘C’ C Program Structure

The document outlines the structure of a C program, emphasizing the importance of the main() function as the entry point and the use of preprocessing commands and header files. It explains the role of stdio.h for input and output functions and provides a simple example of a C program that prints 'Hello World'. Additionally, it highlights the requirement for the main() function to return an integer value, adhering to ANSI C standards.

Uploaded by

nayecool37
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)
9 views

Lect 3 Programming Logic Using ‘C’ C Program Structure

The document outlines the structure of a C program, emphasizing the importance of the main() function as the entry point and the use of preprocessing commands and header files. It explains the role of stdio.h for input and output functions and provides a simple example of a C program that prints 'Hello World'. Additionally, it highlights the requirement for the main() function to return an integer value, adhering to ANSI C standards.

Uploaded by

nayecool37
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
You are on page 1/ 9

Programming Logic Using ‘C’

BCAC0001
Lect-3 C Program Structure
Presented by:
Atul Kumar Uttam
Assistant Professor
Computer Engineering & Applications Department,
GLA University, Mathura
[email protected], +91-8979593001
C Program Structure
/*Comments*/ Optional, description of program
preprocessing commands To include header files, macro declaration
global Declarations; Optional, declare variables common to all functions
int main() Entry point of the program
{
Compulsory, user defined functions,
local declaration; start point of the program
executable statements;
Body of main function
-
return 0;
}
user defined functions()
{ Optional
fun definition
BCAC0001 Programming Logic using C :
} Atul Kr Uttam
A simple C program

#include<stdio.h>
int main(void)
{
printf(“Hello World”);
return 0;
}

BCAC0001 Programming Logic using C :


Atul Kr Uttam
The #include Directive
• Instructs the compiler to include the contents of the
file (stdio.h)
• Always begin with a # character

• Do not end with a semicolon ;

BCAC0001 Programming Logic using C :


Atul Kr Uttam
stdio.h
• stdio.h (standard input output)
• Contains declarations of data input and output
functions

printf(), scanf()

• Order of inclusion of header files does not matter

BCAC0001 Programming Logic using C :


Atul Kr Uttam
Brackets <file_name>
• The compiler searches in system dependent predefined
directories, where system files reside.

• "file_name" the compiler usually begins with the


directory of the source file(pwd), then searches the
predefined directories.

• If the file is not found, the compiler will produce an error


message and the compilation fails.

BCAC0001 Programming Logic using C :


Atul Kr Uttam
The main() Function
• Every C program must contain at least one function
• main( ) is a compulsory function
• Pre-declared
• User defined
• Tells the entry point of the program

BCAC0001 Programming Logic using C :


Atul Kr Uttam
int main() Function
• Called automatically when the program runs, by OS.

• The execution of the program ends


– when the last statement of main() is executed,
– unless an exit statement such as return is called earlier.

• The keyword int indicates that main() must return an


integer to the operating system when it terminates.

• The value 0 indicates normal termination.

BCAC0001 Programming Logic using C :


Atul Kr Uttam
The main() Function
• You may see other declarations such as:
void main()
• It is illegal according to the ANSI C standard because main()
must return a value.

• Because the return type is int by default, it is allowed to omit


the word int and write
main( )
{

BCAC0001 Programming Logic using C :


Atul Kr Uttam

You might also like