SlideShare a Scribd company logo
C Programming
By
Mrs. B. Dhivya M.C.A., M.Phil.,(Ph.D).,
Technical Trainer / Assistant Professor, Department of Computer Science,
Sri Ramakrishna College of Arts & Science, Coimbatore.
C Basics
Agenda
• What is C Language?
• History of C
• Features of C
• Structure of C Programs
• Tokens in C
What is C Language?
• C is a general-purpose, procedural, high-level
programming language.
• C language was developed by Dennis M. Ritchie at the
Bell Telephone Laboratories in 1972.
• It is a powerful and flexible language which was first
developed for the programming of the UNIX operating
System.
• C is one of the most widely used programming languages.
• C programming language is known for its simplicity and
efficiency.
History of C
Features of C
C Programming - Basics of c -history of c
EXAMPLE PROGRAM
#include <stdio.h>
#include<conio.h>
void main()
{
printf("Hiii, Studentsn");
getch();
}
Standard I/O
Standard Input :
printf() - This function stands for "print formatted" and is used for formatted
output. It allows you to specify the format of the output by using format
specifies like %d for integers, %f for floats, %s for strings, etc.
int num = 10;
printf("The number is: %dn", num);
Standard Output:
scanf() is a function in C programming used for taking input from the user. It
reads formatted data from the standard input (usually the keyboard) and
assigns the values to the variables passed as arguments.
scanf("%d", &num); // Reads an integer input from the user and stores it in
'num
Tokens in C
A token in C can be defined as the smallest individual element
of the C programming language that is meaningful to the
compiler. It is the basic component of a C program.
Keywords
The keywords are pre-defined or reserved words in a
programming language. Each keyword is meant to perform a
specific function in a program. C language
supports 32 keywords.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Identifiers
•Identifiers are used as the general terminology for the
naming of variables, functions, and arrays.
•These are user-defined names consisting of an arbitrarily
long sequence of letters and digits with either a letter or the
underscore(_) as a first character.
•Identifier names must differ in spelling and case from any
keywords.
Constants
The constants refer to the variables with fixed values. They are
like normal variables but with the difference that their values
can not be modified in the program once they are defined.
Constants may belong to any of the data types.
Examples of Constants in C
const int c_var = 20;
const int* const ptr = &c_var;
Strings
Strings are nothing but an array of characters ended with a null
character (‘0’). This null character indicates the end of the
string. Strings are always enclosed in double quotes. Whereas, a
character is enclosed in single quotes in C.
Examples of String
char str[20] = {‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘f’, ‘o’, ‘r’, ‘g’, ’e’, ‘e’, ‘k’,
‘s’, ‘0’};
char str[20] = “geeksforgeeks”;
Char s1[] = “geeksforgeeks”;
Special Symbols
Special symbols are used in C having some special
meaning and thus, cannot be used for some other purpose.
Brackets[]: Opening and closing brackets are used as array element references. These indicate
single and multidimensional subscripts.
Parentheses(): These special symbols are used to indicate function calls and function parameters.
Braces{}: These opening and ending curly braces mark the start and end of a block of code
containing more than one executable statement.
Comma (, ): It is used to separate more than one statement like for separating parameters in function
calls.
Colon(:): It is an operator that essentially invokes something called an initialization list.
Semicolon(;): It is known as a statement terminator. It indicates the end of one logical entity. That’s
why each individual statement must be ended with a semicolon.
Asterisk (*): It is used to create a pointer variable and for the multiplication of variables.
Assignment operator(=): It is used to assign values and for logical operation validation.
Pre-processor (#): The preprocessor is a macro processor that is used automatically by the compiler
to transform your program before actual compilation.
Period (.): Used to access members of a structure or union.
Tilde(~): Used as a destructor to free some space from memory.
Operators
Operators are symbols that trigger an action when applied to C variables and
other objects. The data items on which operators act are called operands.
Unary Operators: Those operators that require only a single operand to act
upon are known as unary operators. For Example increment and decrement
operators
Binary Operators: Those operators that require two operands to act upon
are called binary operators. Binary operators can further are classified into:
Arithmetic operators
Relational Operators
Logical Operators
Assignment Operators
Bitwise Operator
Ternary Operator: The operator that requires three operands to act upon is
called the ternary operator. Conditional Operator(?) is also called the ternary
operator.
Activity - 1
Program to Print an Integer
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: “, number); // reads and
stores input
scanf("%d", &number); // displays output
printf("You entered: %d", number);
return 0;
}
Output
Enter an integer:5
You entered:5
Activity - 2
Write a Program to Add Two Integers:.
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter two integers: “,num1, num2);
scanf("%d %d", &num1, &num2);
// calculate the sum
sum = num1 + num2;
printf("%d + %d = %d", num1, num2, sum);
return 0;
}
Output
Enter two integers: 12
11
12 + 11 = 23
Predict the Output or error of the C Program
1. void main()
{
int const * p=5;
printf("%d",++(*p));
}
Answer: Compiler error: Cannot modify a constant
value.
Explanation: p is a pointer to a "constant integer".
But we tried to change the value of the
"constant integer".
2. main()
{
printf("nab");
printf("bsi");
printf("rha");
}
Answer: hai
Explanation:
n (Newline): This escape sequence moves the cursor to the beginning of the
next line. When printf encounters n, it moves the cursor to the next line,
starting from the beginning.
b (Backspace): This escape sequence moves the cursor back one position
but doesn’t erase any character. When printf encounters b, it moves the
cursor back without clearing any character.
r (Carriage Return): This escape sequence moves the cursor to the
beginning of the current line without advancing to the next line. Any
characters printed after r overwrite the existing characters on that line.
3. #define clrscr() 100
main()
{
clrscr();
printf("%dn",clrscr());
}
Answer: 100
Explanation: Preprocessor executes as a seperate pass before the
execution of the compiler. So textual replacement of clrscr() to
100 occurs.
4. main()
{
printf("%p",main);
}
Answer: Some address will be printed.
Explanation: Function names are just addresses (just like
array names are addresses). main() is also a function. So the
address of function main will be printed. %p in printf
specifies that the argument is an address. They are printed
as hexadecimal numbers.
5. main()
{
clrscr();
}
clrscr();
Answer: No output/error
Explanation: The first clrscr() occurs inside a function.
So it becomes a function call. In the second clrscr(); is a
function declaration (because it is not inside any
function).
6. main()
{
int i=400,j=300;
printf("%d..%d");
}
Answer: 400..300
Explanation: printf takes the values of the first
two assignments of the program. Any number
of printf's may be given. All of them take only
the first two values. If more number of
assignments given in the program,then printf
will take garbage value
7. #include <stdio.h>
main()
{
int i=1,j=2;
switch(i)
{ case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
Answer: Compiler Error: Constant expression required in
function main.
Explanation: The case statement can have only constant
expressions (this implies that we cannot use variable names
directly so an error).
Assessment 1
1. Program to check if the given character is a vowel or consonant .
2. C Program to Find the Largest Number Among Three Numbers

More Related Content

Similar to C Programming - Basics of c -history of c (20)

C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
jatin batra
 
c programming session 1.pptx
c programming session 1.pptxc programming session 1.pptx
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
Thooyavan Venkatachalam
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
Cpu
CpuCpu
Cpu
Mohit Jain
 
C language ppt
C language pptC language ppt
C language ppt
Ğäùråv Júñêjå
 
Aniket tore
Aniket toreAniket tore
Aniket tore
anikettore1
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Basics of C porgramming
Basics of C porgrammingBasics of C porgramming
Basics of C porgramming
baabtra.com - No. 1 supplier of quality freshers
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Muthuganesh S
 
C and DS -unit 1 -Artificial Intelligence and ML.docx
C and DS -unit 1 -Artificial Intelligence  and ML.docxC and DS -unit 1 -Artificial Intelligence  and ML.docx
C and DS -unit 1 -Artificial Intelligence and ML.docx
msurfudeen6681
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
Gagan Deep
 
C Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptxC Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptx
kumaranand07297
 
C PADHLO FRANDS.pdf
C PADHLO FRANDS.pdfC PADHLO FRANDS.pdf
C PADHLO FRANDS.pdf
RishiBhardwaj65
 
C programming.pdf
C programming.pdfC programming.pdf
C programming.pdf
JitendraYadav351971
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
jatin batra
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
C and DS -unit 1 -Artificial Intelligence and ML.docx
C and DS -unit 1 -Artificial Intelligence  and ML.docxC and DS -unit 1 -Artificial Intelligence  and ML.docx
C and DS -unit 1 -Artificial Intelligence and ML.docx
msurfudeen6681
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
Gagan Deep
 
C Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptxC Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptx
kumaranand07297
 

Recently uploaded (20)

European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Ad

C Programming - Basics of c -history of c

  • 1. C Programming By Mrs. B. Dhivya M.C.A., M.Phil.,(Ph.D)., Technical Trainer / Assistant Professor, Department of Computer Science, Sri Ramakrishna College of Arts & Science, Coimbatore. C Basics
  • 2. Agenda • What is C Language? • History of C • Features of C • Structure of C Programs • Tokens in C
  • 3. What is C Language? • C is a general-purpose, procedural, high-level programming language. • C language was developed by Dennis M. Ritchie at the Bell Telephone Laboratories in 1972. • It is a powerful and flexible language which was first developed for the programming of the UNIX operating System. • C is one of the most widely used programming languages. • C programming language is known for its simplicity and efficiency.
  • 7. EXAMPLE PROGRAM #include <stdio.h> #include<conio.h> void main() { printf("Hiii, Studentsn"); getch(); }
  • 8. Standard I/O Standard Input : printf() - This function stands for "print formatted" and is used for formatted output. It allows you to specify the format of the output by using format specifies like %d for integers, %f for floats, %s for strings, etc. int num = 10; printf("The number is: %dn", num); Standard Output: scanf() is a function in C programming used for taking input from the user. It reads formatted data from the standard input (usually the keyboard) and assigns the values to the variables passed as arguments. scanf("%d", &num); // Reads an integer input from the user and stores it in 'num
  • 9. Tokens in C A token in C can be defined as the smallest individual element of the C programming language that is meaningful to the compiler. It is the basic component of a C program.
  • 10. Keywords The keywords are pre-defined or reserved words in a programming language. Each keyword is meant to perform a specific function in a program. C language supports 32 keywords. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
  • 11. Identifiers •Identifiers are used as the general terminology for the naming of variables, functions, and arrays. •These are user-defined names consisting of an arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first character. •Identifier names must differ in spelling and case from any keywords.
  • 12. Constants The constants refer to the variables with fixed values. They are like normal variables but with the difference that their values can not be modified in the program once they are defined. Constants may belong to any of the data types. Examples of Constants in C const int c_var = 20; const int* const ptr = &c_var;
  • 13. Strings Strings are nothing but an array of characters ended with a null character (‘0’). This null character indicates the end of the string. Strings are always enclosed in double quotes. Whereas, a character is enclosed in single quotes in C. Examples of String char str[20] = {‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘f’, ‘o’, ‘r’, ‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘0’}; char str[20] = “geeksforgeeks”; Char s1[] = “geeksforgeeks”;
  • 14. Special Symbols Special symbols are used in C having some special meaning and thus, cannot be used for some other purpose. Brackets[]: Opening and closing brackets are used as array element references. These indicate single and multidimensional subscripts. Parentheses(): These special symbols are used to indicate function calls and function parameters. Braces{}: These opening and ending curly braces mark the start and end of a block of code containing more than one executable statement. Comma (, ): It is used to separate more than one statement like for separating parameters in function calls. Colon(:): It is an operator that essentially invokes something called an initialization list. Semicolon(;): It is known as a statement terminator. It indicates the end of one logical entity. That’s why each individual statement must be ended with a semicolon. Asterisk (*): It is used to create a pointer variable and for the multiplication of variables. Assignment operator(=): It is used to assign values and for logical operation validation. Pre-processor (#): The preprocessor is a macro processor that is used automatically by the compiler to transform your program before actual compilation. Period (.): Used to access members of a structure or union. Tilde(~): Used as a destructor to free some space from memory.
  • 15. Operators Operators are symbols that trigger an action when applied to C variables and other objects. The data items on which operators act are called operands. Unary Operators: Those operators that require only a single operand to act upon are known as unary operators. For Example increment and decrement operators Binary Operators: Those operators that require two operands to act upon are called binary operators. Binary operators can further are classified into: Arithmetic operators Relational Operators Logical Operators Assignment Operators Bitwise Operator Ternary Operator: The operator that requires three operands to act upon is called the ternary operator. Conditional Operator(?) is also called the ternary operator.
  • 16. Activity - 1 Program to Print an Integer #include <stdio.h> int main() { int number; printf("Enter an integer: “, number); // reads and stores input scanf("%d", &number); // displays output printf("You entered: %d", number); return 0; }
  • 18. Activity - 2 Write a Program to Add Two Integers:. #include <stdio.h> int main() { int num1, num2, sum; printf("Enter two integers: “,num1, num2); scanf("%d %d", &num1, &num2); // calculate the sum sum = num1 + num2; printf("%d + %d = %d", num1, num2, sum); return 0; }
  • 19. Output Enter two integers: 12 11 12 + 11 = 23
  • 20. Predict the Output or error of the C Program 1. void main() { int const * p=5; printf("%d",++(*p)); } Answer: Compiler error: Cannot modify a constant value. Explanation: p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
  • 21. 2. main() { printf("nab"); printf("bsi"); printf("rha"); } Answer: hai Explanation: n (Newline): This escape sequence moves the cursor to the beginning of the next line. When printf encounters n, it moves the cursor to the next line, starting from the beginning. b (Backspace): This escape sequence moves the cursor back one position but doesn’t erase any character. When printf encounters b, it moves the cursor back without clearing any character. r (Carriage Return): This escape sequence moves the cursor to the beginning of the current line without advancing to the next line. Any characters printed after r overwrite the existing characters on that line.
  • 22. 3. #define clrscr() 100 main() { clrscr(); printf("%dn",clrscr()); } Answer: 100 Explanation: Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.
  • 23. 4. main() { printf("%p",main); } Answer: Some address will be printed. Explanation: Function names are just addresses (just like array names are addresses). main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.
  • 24. 5. main() { clrscr(); } clrscr(); Answer: No output/error Explanation: The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).
  • 25. 6. main() { int i=400,j=300; printf("%d..%d"); } Answer: 400..300 Explanation: printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take only the first two values. If more number of assignments given in the program,then printf will take garbage value
  • 26. 7. #include <stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } } Answer: Compiler Error: Constant expression required in function main. Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).
  • 27. Assessment 1 1. Program to check if the given character is a vowel or consonant . 2. C Program to Find the Largest Number Among Three Numbers