Download presentation
Presentation is loading. Please wait.
1
History of C and basics of Programming
2
We need a compiler first
Please install any C compiler in your machine Suggested: Gnu Compiler Collection (gcc) Others:
3
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer – person who writes instructions (programs) to make computer perform a task
4
Main Hardware Component Categories
Central Processing Unit Input Device Output Device Main Memory Secondary Storage Devices
5
Main Memory Holds both program instructions and data
Volatile – erased when program terminates or computer is turned off Also called Random Access Memory (RAM)
6
Main Memory Organization
Bit Smallest piece of memory Stands for binary digit Has values 0 (off) or 1 (on) Byte Is 8 consecutive bits Word Usually 4 consecutive bytes Has an address 8 bits 1 byte
7
What is C C is a very powerful complied system programming language
Introduced by Dennis Ritchie sometime between 1969 and 1973 at AT&T Bell Labs C is a procedural programming paradigm C allows for recursion and lexical variable scope all while using static typing to help prevent unintentional errors
8
Example of a C program
9
What do you need to write and execute a C program
Text editor to write your code (source file). Suggested : notepad++ Compiler to convert human-readable source code into machine-readable machine code (executable/.exe file) Inbuilt cmd shell or terminal in your machine to see the output Note: C source file usually end with .c
10
C applications C is used where speed, space, and portability are important. Most operating systems are written in C. Most other computer languages are also written in C. And most game software is written in C.
11
Anatomy of a C program C programs normally begin with a comment.
The comment starts with /* The comment ends with */ Next comes the include section Finally you will find in a source file are the functions
12
Comments. Anatomy of a C program
The comment starts with /* The comment ends with */ Comment describes the purpose of the code in the file, and might include some license or copyright information. There’s no need to include a comment at the beginning or anywhere else in the file. But it’s good practice and what most C programmers will expect to find.
13
Include section Anatomy of a C program
Almost every C can do nothing without the help of the external libraries. Libraries are nothing but an external code that is written by somebody. You will need to tell the compiler what external code to use by including header files for the relevant libraries. stdio.h is the most popular library, you will see this very often. The stdio library contains code that allows you to read and write data from and to the terminal.
14
Functions Anatomy of a C program
All C code runs inside functions. The most important function you will find in any C program is called the main() function. The main() function is the starting point for all of the code in your program.
15
What is main() function
function body The computer will start running any program from the main() function, the program doesn't start without this function. main() function has a return type of int return values are needed to to decide if the program ran successfully or not. For example, if you tell your main() function to return 0, this means that the program was successful. If any other value is returned, there was a problem in executing your code. The function body must be surrounded by braces.
16
Homework Install compiler in your machine and run the below code
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.