SlideShare una empresa de Scribd logo
1 de 31
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program comment and preprocessor directives basic data types data declarations statements Basic functions
Program is created in the Editor and  stored on Disk.    Editor Phase 1 : Disk Disk Compiler  creates object code and stores  it  on Disk. Compiler Phase 3 : Disk Linker links object  code with libraries,  creates a.out and  stores it  on Disk.     Linker  Phase 4 : Disk C Development Environment Preprocessor program processes the  code.    Preprocessor Phase 2 :
  Primary   Memory Loader  Phase 5 : Loader puts Program in Memory : . Primary   Memory C P U Phase 6 : CPU takes each instruction and  executes it, storing new data values as the program executes. : .
From code to executables Source  Code Pre-processor     Compiler Assembly  Code   Assembler Libraries   Object   Code       Linker    Executable Code
A Simple Program Example #include <stdio.h> main() { 	printf("Programming in C is easy."); } Sample Program Output Programming in C is easy.
[object Object],In C, lowercase and uppercase characters are very important! All commands in C must be lowercase. The C programs starting point is identified by the word  	main() 	This informs the computer as to where the program actually starts. The brackets that follow the keyword main indicate that there are no arguments supplied to this program (this will be examined later on). 	The two braces, { and }, signify the begin and end segments of the program.
The purpose of the statement 	#include <stdio.h> 	is to allow the use of the printf statement to provide program output. Text to be displayed by printf() must be enclosed in double quotes. The program has only one statement  	printf("Programming in C is easy."); 	printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes "", it is printed without modification. There are some exceptions however.
	This has to do with the and % characters. These characters are modifiers, and for the present the followed by the n character represents a newline character.  	Thus the program prints Programming in C is easy. and the cursor is set to the beginning of the next line. As we shall see later on, what follows the character will determine what is printed, ie, a tab, clear screen, clear line etc. Another important thing to remember is that all C statements are terminated by a semi-colon ;
[object Object]
program execution begins at main()
keywords are written in lower-case
statements are terminated with a semi-colon
text strings are enclosed in double quotes,[object Object]
A token is a language element that can be used in forming higher level language constructs Equivalent to a ‘word’ in English language Several types of tokens can be used to build a higher level C language construct such as expressions and statements There are 6 kinds of tokens in C: Reserved words (keywords) Identifiers Constants String literals Punctuators Operators
Reserved Words Keywords that identify language entities such as statements, data types, language attributes, etc. Have special meaning to the compiler, cannot be used as identifiers in our program. Should be typed in lowercase. Example: const, double, int, main, void, while, for, else (etc..)
Identifiers Words used to represent certain program entities (program variables, function names, etc). Example: int my_name;  my_name is an identifier used as a program variable void CalculateTotal(int value) CalculateTotal is an identifier used as a function name
Constants Entities that appear in the program code as fixed values. 4 types of constants: Integer constants Positive or negative whole numbers with no fractional part Example:  const int MAX_NUM = 10; const int MIN_NUM = -90; Floating-point constants Positive or negative decimal numbers with an integer part, a decimal point and a fractional part Example: const double VAL = 0.5877e2; (stands for 0.5877 x 102)
Character constants A character enclosed in a single quotation mark Example: const char letter = ‘n’; const char number = ‘1’; printf(“%c”, ‘S’); Output would be: S Enumeration Values are given as a list Example:
String Literals A sequence of any number of characters surrounded by double quotation marks.  Example: “REFORMASI” “My name is Salman” Example of usage in C program: printf(“My room number is BN-1-012”); Output: My room number is BN-1-012
Punctuators (separators) Symbols used to separate different parts of the C program. These punctuators include: [ ] ( ) { } , ; “: * # Usage example:
Operators Tokens that result in some kind of computation or action when applied to variables or or other elements in an expression. Example of operators: * + = - / Usage example: result = total1 + total2;
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable declaration Variable definition
Comments Explanations or annotations that are included in a program for documentation and clarification purpose. Completely ignored by the compiler during compilation and have no effect on program execution. Starts with ‘/*’ and ends with ‘*/’ Some compiler support comments starting with ‘//’
Preprocessor Directives The first thing to be checked by the compiler. Starts with ‘#’. Tell the compiler about specific options that it needs to be aware of during compilation. There are a few compiler directives. But only 2 of them will be discussed here. #include <stdio.h> Tell the compiler to include the file stdio.h during compilation Anything in the header file is considered a part of the program #define VALUE 10 Tell the compiler to substitute the word VALUE with 10 during compilation
Basic Data Types 3 examples of basic data types: int (used to declare numeric program variables of integer type) char (used to declare character variable) double (used to declare floating point variable) In addition, there are float, void, short, long, etc. Declaration: specifies the type of a variable. Example: int local_var; Definition: assigning a value to the declared variable. Example: local_var = 5;
A variable can be declared globally or locally. A globally declared variable can be accessed from all parts of the program. A locally declared variable can only be accessed from inside the function in which the variable is declared.
Statements A specification of an action to be taken by the computer as the program executes. In the previous example, there are 2 lines following variable declaration and variable definition that terminate with semicolon ‘;’.  global_var = local_var + VALUE; printf (“Total sum is: %d”, global_var); Each line is a statement.
Basic Functions A C program consists of one or more functions that contain a group of statements which perform a specific task. A C program must at least have one function: the function main. We can create our own function or use the functions that has been created in the library, in which case we have to include the appropriate header file (example: stdio.h).
In this section, we will learn a few functions that are pre-defined in the header file stdio.h These functions are: printf() scanf() getchar() & putchar()  In addition to those functions, we will also learn about Format Specifier and Escape Sequence which are used with printf() and scanf().
printf() Used to send data to the standard output (usually the monitor) to be printed according to specific format. General format: printf(“control string”, variables); Control string is a combination of text, format specifier and escape sequence. Example: printf(“Thank you”); printf (“Total sum is: %d”, global_var); %d is a format specifier  is an escape sequence
Format Specifier Tells the printf() function the format of the output to be printed put.

Más contenido relacionado

La actualidad más candente

C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for universitySheikh Monirul Hasan
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTBatra Centre
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingSivant Kolhe
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingManoj Tyagi
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Rumman Ansari
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming languagesanjay joshi
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of cHarish Kumawat
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in CMuthuganesh S
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 

La actualidad más candente (20)

Presentation on C programming language
Presentation on C programming languagePresentation on C programming language
Presentation on C programming language
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
C programming notes
C programming notesC programming notes
C programming notes
 
Chapter3
Chapter3Chapter3
Chapter3
 
C language
C languageC language
C language
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
History of c
History of cHistory of c
History of c
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
C Language
C LanguageC Language
C Language
 
Enums in c
Enums in cEnums in c
Enums in c
 

Similar a C basics 4 std11(GujBoard)

Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programmingMithun DSouza
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I vampugani
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.pptatulchaudhary821
 
C programming course material
C programming course materialC programming course material
C programming course materialRanjitha Murthy
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 

Similar a C basics 4 std11(GujBoard) (20)

Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
C programming
C programmingC programming
C programming
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
C programming
C programmingC programming
C programming
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C programming course material
C programming course materialC programming course material
C programming course material
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

C basics 4 std11(GujBoard)

  • 1. Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program comment and preprocessor directives basic data types data declarations statements Basic functions
  • 2. Program is created in the Editor and stored on Disk. Editor Phase 1 : Disk Disk Compiler creates object code and stores it on Disk. Compiler Phase 3 : Disk Linker links object code with libraries, creates a.out and stores it on Disk. Linker Phase 4 : Disk C Development Environment Preprocessor program processes the code. Preprocessor Phase 2 :
  • 3. Primary Memory Loader Phase 5 : Loader puts Program in Memory : . Primary Memory C P U Phase 6 : CPU takes each instruction and executes it, storing new data values as the program executes. : .
  • 4. From code to executables Source Code Pre-processor Compiler Assembly Code Assembler Libraries Object Code Linker Executable Code
  • 5. A Simple Program Example #include <stdio.h> main() { printf("Programming in C is easy."); } Sample Program Output Programming in C is easy.
  • 6.
  • 7. The purpose of the statement #include <stdio.h> is to allow the use of the printf statement to provide program output. Text to be displayed by printf() must be enclosed in double quotes. The program has only one statement printf("Programming in C is easy."); printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes "", it is printed without modification. There are some exceptions however.
  • 8. This has to do with the and % characters. These characters are modifiers, and for the present the followed by the n character represents a newline character. Thus the program prints Programming in C is easy. and the cursor is set to the beginning of the next line. As we shall see later on, what follows the character will determine what is printed, ie, a tab, clear screen, clear line etc. Another important thing to remember is that all C statements are terminated by a semi-colon ;
  • 9.
  • 11. keywords are written in lower-case
  • 12. statements are terminated with a semi-colon
  • 13.
  • 14. A token is a language element that can be used in forming higher level language constructs Equivalent to a ‘word’ in English language Several types of tokens can be used to build a higher level C language construct such as expressions and statements There are 6 kinds of tokens in C: Reserved words (keywords) Identifiers Constants String literals Punctuators Operators
  • 15. Reserved Words Keywords that identify language entities such as statements, data types, language attributes, etc. Have special meaning to the compiler, cannot be used as identifiers in our program. Should be typed in lowercase. Example: const, double, int, main, void, while, for, else (etc..)
  • 16. Identifiers Words used to represent certain program entities (program variables, function names, etc). Example: int my_name; my_name is an identifier used as a program variable void CalculateTotal(int value) CalculateTotal is an identifier used as a function name
  • 17. Constants Entities that appear in the program code as fixed values. 4 types of constants: Integer constants Positive or negative whole numbers with no fractional part Example: const int MAX_NUM = 10; const int MIN_NUM = -90; Floating-point constants Positive or negative decimal numbers with an integer part, a decimal point and a fractional part Example: const double VAL = 0.5877e2; (stands for 0.5877 x 102)
  • 18. Character constants A character enclosed in a single quotation mark Example: const char letter = ‘n’; const char number = ‘1’; printf(“%c”, ‘S’); Output would be: S Enumeration Values are given as a list Example:
  • 19. String Literals A sequence of any number of characters surrounded by double quotation marks. Example: “REFORMASI” “My name is Salman” Example of usage in C program: printf(“My room number is BN-1-012”); Output: My room number is BN-1-012
  • 20. Punctuators (separators) Symbols used to separate different parts of the C program. These punctuators include: [ ] ( ) { } , ; “: * # Usage example:
  • 21. Operators Tokens that result in some kind of computation or action when applied to variables or or other elements in an expression. Example of operators: * + = - / Usage example: result = total1 + total2;
  • 22. Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable declaration Variable definition
  • 23. Comments Explanations or annotations that are included in a program for documentation and clarification purpose. Completely ignored by the compiler during compilation and have no effect on program execution. Starts with ‘/*’ and ends with ‘*/’ Some compiler support comments starting with ‘//’
  • 24. Preprocessor Directives The first thing to be checked by the compiler. Starts with ‘#’. Tell the compiler about specific options that it needs to be aware of during compilation. There are a few compiler directives. But only 2 of them will be discussed here. #include <stdio.h> Tell the compiler to include the file stdio.h during compilation Anything in the header file is considered a part of the program #define VALUE 10 Tell the compiler to substitute the word VALUE with 10 during compilation
  • 25. Basic Data Types 3 examples of basic data types: int (used to declare numeric program variables of integer type) char (used to declare character variable) double (used to declare floating point variable) In addition, there are float, void, short, long, etc. Declaration: specifies the type of a variable. Example: int local_var; Definition: assigning a value to the declared variable. Example: local_var = 5;
  • 26. A variable can be declared globally or locally. A globally declared variable can be accessed from all parts of the program. A locally declared variable can only be accessed from inside the function in which the variable is declared.
  • 27. Statements A specification of an action to be taken by the computer as the program executes. In the previous example, there are 2 lines following variable declaration and variable definition that terminate with semicolon ‘;’. global_var = local_var + VALUE; printf (“Total sum is: %d”, global_var); Each line is a statement.
  • 28. Basic Functions A C program consists of one or more functions that contain a group of statements which perform a specific task. A C program must at least have one function: the function main. We can create our own function or use the functions that has been created in the library, in which case we have to include the appropriate header file (example: stdio.h).
  • 29. In this section, we will learn a few functions that are pre-defined in the header file stdio.h These functions are: printf() scanf() getchar() & putchar() In addition to those functions, we will also learn about Format Specifier and Escape Sequence which are used with printf() and scanf().
  • 30. printf() Used to send data to the standard output (usually the monitor) to be printed according to specific format. General format: printf(“control string”, variables); Control string is a combination of text, format specifier and escape sequence. Example: printf(“Thank you”); printf (“Total sum is: %d”, global_var); %d is a format specifier is an escape sequence
  • 31. Format Specifier Tells the printf() function the format of the output to be printed put.
  • 32. Escape Sequence Escape sequence is used in the printf() function to do something to the output.
  • 33. scanf() Read data from the standard input device (usually keyboard) and store it in a variable. General format: scanf(“Control string”, &variable); The general format is pretty much the same as printf() except that it passes the address of the variable (notice the & sign) instead of the variable itself to the second function argument. Example:
  • 34. getchar() and putchar() getchar() - read a character from standard input putchar() - write a character to standard output Example: #include <stdio.h> void main(void) { char my_char; printf(“Please type a character: “); my_char = getchar(); printf(“You have typed this character: “); putchar(my_char); }