Rajkiya Engineering College
Ambedkar Nagar Uttar Pradesh
Presentation on:-
C and C++ Programming Basic
Presented by:- Purushottam Presented to:-
Roll no:- 2107370200033 Mrs:-Mona Rani
Branch:- Electrical Engineering Department Of Electrical Engg…..
Contents:-
 Introduction
 Data Types
 Operators
 C++ Conditions
 Function
 Classes and Objects
 Advantages
Introduction of C and C++
About C
 C is a general-purpose programming language created by Dennis Ritchie at the Bell
Laboratories in 1972. It is a very popular language, despite being old.
 The main reason for its popularity is because it is a fundamental language in the field of
computer science.
About C++
 C++ is one of the world's most popular programming languages. C++ can be found in today's
operating systems, Graphical User Interfaces, and embedded systems.
 C++ is an object-oriented programming language which gives a clear structure to programs
and allows code to be reused, lowering development costs.
Difference between C and C++
 C++ was developed as an extension of C, and both languages have almost the same syntax.
 The main difference between C and C++ is that C++ support classes and objects, while C does
not.
History
 C++ was developed by Bjarne Stroustrup at Bell Laboratories over a period
starting in 1979.
 Since C++ is an attempt to add object-oriented features (plus other
improvements) to C, earlier it was called as “C with Objects”.
 As the language developed, Stroustrup named it as C++ in 1983.
 The name C++ suggests “C incremented” (recall the ++ is an increment operator
of C).
Data Types
The data type is a collection of data with values having fixed values, meaning as well as
its characteristics
Operator
An operator is a symbol that operates on a value to perform specific
mathematical or logical computations.
Types of Operators
Relational Operator
Arithmetic Operator
Comparison Operator
Relational Operator
 The relational operators are used to compare two of the available values to understand
what relationship the pairs of values share.
Arithmetic Operator
 Arithmetic operators are used to perform common mathematical operations.
Example
int sum1 = 100 + 50; // 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400)
Comparison Operator
 Comparison operators are used to compare two values (or variables). This is important in
programming, because it helps us to find answers and make decisions.
 The return value of a comparison is either 1 or 0, which means true (1) or false (0). These
values are known as Boolean values, and you will learn more about them in the Booleans
and If..Else chapter.
 In the following example, we use the greater than operator (>) to find out if 5 is greater
than 3:
Example
int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3
C++ Conditions-
 A conditional statement, also known as a selection statement, facilitates the making of
decisions on the basis of particular conditions.
 Less than: a < b
 Less than or equal to: a <= b
 Greater than: a > b
 Greater than or equal to: a >= b
 Equal to a == b
 Not Equal to: a != b
C++ has the following conditional Statement
Use if to specify a block of code to be executed, if a specified condition is true
Use else to specify a block of code to be executed, if the same condition is false
The if Statements
Use the if statement to specify a block of C++ code to be executed if a condition
is true.

Example
 int x = 20;
int y = 18;
if (x > y) {
cout << "x is greater than y";
}
The else Statement
Use the else statement to specify a block of code to be executed if the condition
is false.
 Example
int time = 20;
if (time < 18) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."
Function
 A function is a block of code which only runs when it is called.
 You can pass data, known as parameters, into a function.
 Functions are used to perform certain actions, and they are important for reusing code: Define the code once,
and use it many times.
 A function can be called multiple times:
 Example:-
 void myFunction() {
cout << "I just got executed!n";
}
int main() {
myFunction();
myFunction();
myFunction();
return 0;
}
// I just got executed!
// I just got executed!
// I just got executed!
Write a program to check
the number is even or odd
Program in C
#include <stdio.h>
int main()
{ int num;
printf("Enter an integer: ");
scanf("%d", &num);
// true if num is perfectly divisible by 2
if(num % 2 == 0)
printf("%d is even.", num);
else printf("%d is odd.", num);
return 0;
}
Output- Enter an integer
Program in C++
#include <iostream>
using namespace std; int main()
{ int a;
cout << "Enter the number: "; cin >> a; /* logic */
if (a % 2 == 0) {
cout << "The given number is EVEN" << endl; }
else {
cout << "The given number is ODD" << endl; } return 0; }
Program Output:
Enter the number: 8
The given number is EVEN
Advantage of C++
• Object-Oriented. C++ is an object-oriented programming
language which means that the main focus is on objects and
manipulations around these objects. ...
• Speed. ...
• Compiled. ...
• Rich Library Support. ...
• Pointer Support. ...
• Closer to Hardware.
Thank
You

C and C++ programming basics for Beginners.pptx

  • 1.
    Rajkiya Engineering College AmbedkarNagar Uttar Pradesh Presentation on:- C and C++ Programming Basic Presented by:- Purushottam Presented to:- Roll no:- 2107370200033 Mrs:-Mona Rani Branch:- Electrical Engineering Department Of Electrical Engg…..
  • 2.
    Contents:-  Introduction  DataTypes  Operators  C++ Conditions  Function  Classes and Objects  Advantages
  • 3.
    Introduction of Cand C++ About C  C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old.  The main reason for its popularity is because it is a fundamental language in the field of computer science. About C++  C++ is one of the world's most popular programming languages. C++ can be found in today's operating systems, Graphical User Interfaces, and embedded systems.  C++ is an object-oriented programming language which gives a clear structure to programs and allows code to be reused, lowering development costs. Difference between C and C++  C++ was developed as an extension of C, and both languages have almost the same syntax.  The main difference between C and C++ is that C++ support classes and objects, while C does not.
  • 4.
    History  C++ wasdeveloped by Bjarne Stroustrup at Bell Laboratories over a period starting in 1979.  Since C++ is an attempt to add object-oriented features (plus other improvements) to C, earlier it was called as “C with Objects”.  As the language developed, Stroustrup named it as C++ in 1983.  The name C++ suggests “C incremented” (recall the ++ is an increment operator of C).
  • 5.
    Data Types The datatype is a collection of data with values having fixed values, meaning as well as its characteristics
  • 6.
    Operator An operator isa symbol that operates on a value to perform specific mathematical or logical computations. Types of Operators Relational Operator Arithmetic Operator Comparison Operator
  • 7.
    Relational Operator  Therelational operators are used to compare two of the available values to understand what relationship the pairs of values share.
  • 8.
    Arithmetic Operator  Arithmeticoperators are used to perform common mathematical operations. Example int sum1 = 100 + 50; // 150 (100 + 50) int sum2 = sum1 + 250; // 400 (150 + 250) int sum3 = sum2 + sum2; // 800 (400 + 400)
  • 9.
    Comparison Operator  Comparisonoperators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.  The return value of a comparison is either 1 or 0, which means true (1) or false (0). These values are known as Boolean values, and you will learn more about them in the Booleans and If..Else chapter.  In the following example, we use the greater than operator (>) to find out if 5 is greater than 3: Example int x = 5; int y = 3; cout << (x > y); // returns 1 (true) because 5 is greater than 3
  • 10.
    C++ Conditions-  Aconditional statement, also known as a selection statement, facilitates the making of decisions on the basis of particular conditions.  Less than: a < b  Less than or equal to: a <= b  Greater than: a > b  Greater than or equal to: a >= b  Equal to a == b  Not Equal to: a != b C++ has the following conditional Statement Use if to specify a block of code to be executed, if a specified condition is true Use else to specify a block of code to be executed, if the same condition is false
  • 11.
    The if Statements Usethe if statement to specify a block of C++ code to be executed if a condition is true.  Example  int x = 20; int y = 18; if (x > y) { cout << "x is greater than y"; }
  • 12.
    The else Statement Usethe else statement to specify a block of code to be executed if the condition is false.  Example int time = 20; if (time < 18) { cout << "Good day."; } else { cout << "Good evening."; } // Outputs "Good evening."
  • 13.
    Function  A functionis a block of code which only runs when it is called.  You can pass data, known as parameters, into a function.  Functions are used to perform certain actions, and they are important for reusing code: Define the code once, and use it many times.  A function can be called multiple times:  Example:-  void myFunction() { cout << "I just got executed!n"; } int main() { myFunction(); myFunction(); myFunction(); return 0; } // I just got executed! // I just got executed! // I just got executed!
  • 14.
    Write a programto check the number is even or odd Program in C #include <stdio.h> int main() { int num; printf("Enter an integer: "); scanf("%d", &num); // true if num is perfectly divisible by 2 if(num % 2 == 0) printf("%d is even.", num); else printf("%d is odd.", num); return 0; } Output- Enter an integer Program in C++ #include <iostream> using namespace std; int main() { int a; cout << "Enter the number: "; cin >> a; /* logic */ if (a % 2 == 0) { cout << "The given number is EVEN" << endl; } else { cout << "The given number is ODD" << endl; } return 0; } Program Output: Enter the number: 8 The given number is EVEN
  • 15.
    Advantage of C++ •Object-Oriented. C++ is an object-oriented programming language which means that the main focus is on objects and manipulations around these objects. ... • Speed. ... • Compiled. ... • Rich Library Support. ... • Pointer Support. ... • Closer to Hardware.
  • 16.