SlideShare a Scribd company logo
C PROGRAMMING
LECTURE
1
Recap
2
 C is a high-level language.
 Writing a C code. {editors like gedit, vi}
 Compiling a C code. {gcc –c test.c –o test}
 Executing the object code. {./test}
Some more basics
3
 Keywords
 char, static, if , while, return ..................... Total= about 32
 Data Types
 int , char, float ...………..….. Some more later
 Arithmetic Operators
 + (Plus), - (Minus), * (Multiplication), /(Division)
……….………. Some more later
My first C program!
4
#include <stdio.h>
// program prints hello world
int main() {
printf ("Hello world!");
return 0;
}
Output: Hello world!
Example 1
5
#include <stdio.h>
// program prints a number of type int
int main() {
int number = 4;
printf (“Number is %d”, number);
return 0;
}
Output: Number is 4
Example 2
6
#include <stdio.h>
// program reads and prints the same thing
int main() {
int number ;
printf (“ Enter a Number: ”);
scanf (“%d”, &number);
printf (“Number is %dn”, number);
return 0;
}
Output : Enter a number: 4
Number is 4
more and more
7
#include <stdio.h>
int main() {
/* this program adds
two numbers */
int a = 4; //first number
int b = 5; //second number
int answer = 0; //result
answer = a + b;
}
Note
8
Errors
Compilation
Compiler generally gives the line number at
which the error is present.
Run time
C programs are sequential making the
debugging easier.
Some more Data Types
9
 Primary : int, float, char
 int (signed/unsigned)(2,4Bytes): used to store integers.
 char (signed/unsigned)(1Byte): used to store characters
 float, double(4,8Bytes): used to store a decimal number.
 User Defined:
 typedef: used to rename a data type
 typedef int integer; can use integer to declare an int.
 enum, struct, union
Some more Arithmetic Operators
10
 Prefix Increment : ++a
 example:
 int a=5;
 b=++a; // value of b=6; a=6;
 Postfix Increment: a++
 example
 int a=5;
 b=a++; //value of b=5; a=6;
Contd…
11
 Modulus (remainder): %
 example:
 12%5 = 2;
 Assignment by addition: +=
 example:
 int a=4;
 a+=1; //(means a=a+1) value of a becomes 5
Can use -, /, *, % also
Contd…
12
 Comparision Operators: <, > , <=, >= , !=, ==, !,
&&, || .
 example:
 int a=4, b=5;
 a<b returns a true(non zero number) value.
 Bitwise Operators: <<, >>, ~, &, | ,^ .
 example
 int a=8;
 a= a>>1; // value of a becomes 4
Operator Precedence
13
 Meaning of a + b * c ?
is it a+(b*c) or (a+b)*c ?
 All operators have precedence over each other
 *, / have more precedence over +, - .
 If both *, / are used, associativity comes into
picture. (more on this later)
 example :
 5+4*3 = 5+12= 17.
Precedence Table
14
Highest on top
++ -- (Postfix)
++ -- (Prefix)
* / %
+ -
<< >>
< >
&
|
&&
||
Input / Output
15
 printf (); //used to print to console(screen)
 scanf (); //used to take an input from console(user).
 example: printf(“%c”, ’a’); scanf(“%d”, &a);
 More format specifiers
%c The character format specifier.
%d The integer format specifier.
%i The integer format specifier (same as %d).
%f The floating-point format specifier.
%o The unsigned octal format specifier.
%s The string format specifier.
%u The unsigned integer format specifier.
%x The unsigned hexadecimal format specifier.
%% Outputs a percent sign.
Some more geek stuff
16
 & in scanf.
 It is used to access the address of the variable used.
 example:
 scanf(%d,&a);
 we are reading into the address of a.
 Data Hierarchy.
 example:
 int value can be assigned to float not vice-versa.
 Type casting.
Home Work
17
 Meaning of
 Syntax
 Semantics of a programming language
 Find the Output:
 value=value++ + value++;
 Value=++value + ++value;
 value=value++ + ++value;
End of Today’s Lecture
18
Doubts && Queries?
THANK YOU
19
Ad

More Related Content

Similar to 2. Data, Operators, IO.ppt (20)

the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
floraaluoch3
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
First c program
First c programFirst c program
First c program
Komal Pardeshi
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
Pradipta Mishra
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
Pradipta Mishra
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
SyedHaroonShah4
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
Atul Setu
 
C
CC
C
Khan Rahimeen
 
C
CC
C
Anuja Lad
 
C intro
C introC intro
C intro
Kamran
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
floraaluoch3
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
Pradipta Mishra
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
Pradipta Mishra
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
SyedHaroonShah4
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
C intro
C introC intro
C intro
Kamran
 

Recently uploaded (20)

Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptxIn-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
aptyai
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
DNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in NepalDNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in Nepal
ICT Frame Magazine Pvt. Ltd.
 
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
UXPA Boston
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdfICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Middle East and Africa Cybersecurity Market Trends and Growth Analysis
Middle East and Africa Cybersecurity Market Trends and Growth Analysis Middle East and Africa Cybersecurity Market Trends and Growth Analysis
Middle East and Africa Cybersecurity Market Trends and Growth Analysis
Preeti Jha
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
ICT Frame Magazine Pvt. Ltd.
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
HusseinMalikMammadli
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
Best 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat PlatformsBest 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat Platforms
Soulmaite
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptxIn-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
aptyai
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
UXPA Boston
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdfICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Middle East and Africa Cybersecurity Market Trends and Growth Analysis
Middle East and Africa Cybersecurity Market Trends and Growth Analysis Middle East and Africa Cybersecurity Market Trends and Growth Analysis
Middle East and Africa Cybersecurity Market Trends and Growth Analysis
Preeti Jha
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
MULTI-STAKEHOLDER CONSULTATION PROGRAM On Implementation of DNF 2.0 and Way F...
ICT Frame Magazine Pvt. Ltd.
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
HusseinMalikMammadli
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
Best 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat PlatformsBest 10 Free AI Character Chat Platforms
Best 10 Free AI Character Chat Platforms
Soulmaite
 
Ad

2. Data, Operators, IO.ppt

  • 2. Recap 2  C is a high-level language.  Writing a C code. {editors like gedit, vi}  Compiling a C code. {gcc –c test.c –o test}  Executing the object code. {./test}
  • 3. Some more basics 3  Keywords  char, static, if , while, return ..................... Total= about 32  Data Types  int , char, float ...………..….. Some more later  Arithmetic Operators  + (Plus), - (Minus), * (Multiplication), /(Division) ……….………. Some more later
  • 4. My first C program! 4 #include <stdio.h> // program prints hello world int main() { printf ("Hello world!"); return 0; } Output: Hello world!
  • 5. Example 1 5 #include <stdio.h> // program prints a number of type int int main() { int number = 4; printf (“Number is %d”, number); return 0; } Output: Number is 4
  • 6. Example 2 6 #include <stdio.h> // program reads and prints the same thing int main() { int number ; printf (“ Enter a Number: ”); scanf (“%d”, &number); printf (“Number is %dn”, number); return 0; } Output : Enter a number: 4 Number is 4
  • 7. more and more 7 #include <stdio.h> int main() { /* this program adds two numbers */ int a = 4; //first number int b = 5; //second number int answer = 0; //result answer = a + b; }
  • 8. Note 8 Errors Compilation Compiler generally gives the line number at which the error is present. Run time C programs are sequential making the debugging easier.
  • 9. Some more Data Types 9  Primary : int, float, char  int (signed/unsigned)(2,4Bytes): used to store integers.  char (signed/unsigned)(1Byte): used to store characters  float, double(4,8Bytes): used to store a decimal number.  User Defined:  typedef: used to rename a data type  typedef int integer; can use integer to declare an int.  enum, struct, union
  • 10. Some more Arithmetic Operators 10  Prefix Increment : ++a  example:  int a=5;  b=++a; // value of b=6; a=6;  Postfix Increment: a++  example  int a=5;  b=a++; //value of b=5; a=6;
  • 11. Contd… 11  Modulus (remainder): %  example:  12%5 = 2;  Assignment by addition: +=  example:  int a=4;  a+=1; //(means a=a+1) value of a becomes 5 Can use -, /, *, % also
  • 12. Contd… 12  Comparision Operators: <, > , <=, >= , !=, ==, !, &&, || .  example:  int a=4, b=5;  a<b returns a true(non zero number) value.  Bitwise Operators: <<, >>, ~, &, | ,^ .  example  int a=8;  a= a>>1; // value of a becomes 4
  • 13. Operator Precedence 13  Meaning of a + b * c ? is it a+(b*c) or (a+b)*c ?  All operators have precedence over each other  *, / have more precedence over +, - .  If both *, / are used, associativity comes into picture. (more on this later)  example :  5+4*3 = 5+12= 17.
  • 14. Precedence Table 14 Highest on top ++ -- (Postfix) ++ -- (Prefix) * / % + - << >> < > & | && ||
  • 15. Input / Output 15  printf (); //used to print to console(screen)  scanf (); //used to take an input from console(user).  example: printf(“%c”, ’a’); scanf(“%d”, &a);  More format specifiers %c The character format specifier. %d The integer format specifier. %i The integer format specifier (same as %d). %f The floating-point format specifier. %o The unsigned octal format specifier. %s The string format specifier. %u The unsigned integer format specifier. %x The unsigned hexadecimal format specifier. %% Outputs a percent sign.
  • 16. Some more geek stuff 16  & in scanf.  It is used to access the address of the variable used.  example:  scanf(%d,&a);  we are reading into the address of a.  Data Hierarchy.  example:  int value can be assigned to float not vice-versa.  Type casting.
  • 17. Home Work 17  Meaning of  Syntax  Semantics of a programming language  Find the Output:  value=value++ + value++;  Value=++value + ++value;  value=value++ + ++value;
  • 18. End of Today’s Lecture 18 Doubts && Queries?
  翻译: