0% found this document useful (0 votes)
97 views29 pages

C and C Report

The document provides an overview of the C and C++ programming languages. It discusses key topics like data types, functions, arrays, pointers, and storage classes. The execution of a C program involves creating, compiling, linking, and executing the code. Various operators and expressions are also explained.

Uploaded by

Shivani arya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views29 pages

C and C Report

The document provides an overview of the C and C++ programming languages. It discusses key topics like data types, functions, arrays, pointers, and storage classes. The execution of a C program involves creating, compiling, linking, and executing the code. Various operators and expressions are also explained.

Uploaded by

Shivani arya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Training report on c and c++

Prepared By: Sumit Batra


2809203
Overview of C
C is developed by Dennis Ritchie
C is a structured programming language
C supports functions that enables easy maintainability
of code, by breaking large file into smaller modules
Comments in C provides easy readability
C is a powerful language
Structure Of C Program
Execution Of a C Program
Executing a C program involves following steps:
Creating the program
Compiling of Program
Linking of Program
Execution Of Program
Operators & Expressions
Operator: An operator is a symbol that tells the computer to
perform certain mathematical or logical operations. C supports a set of
Operators.
There are various Operators in C as Follows:
1. Arithmetic Operators
2. Assignment Operators
3. Increment/Decrement Operators
4. Relational Operators
5. Logical Operators
6. Conditional Operators
7. Bitwise Operators
Functions
A Function is a self-contained program segment
that carries out some specific, well-defined task. Each C
program consists of one or more functions . One of these
functions must be called main. Execution of the program will
always begin by carrying out the instructions in main.

Types Of Functions:
C functions can be classified into two categories:
1. Library functions and
2. User-defined functions.
.
Arrays
An Array is a collection of identical data objects which are stored in
consecutive memory locations under a common heading or variable
name. The objects are called elements of the array and are numbered
consecutively 0,1,2,3 and so on. These numbers are called Index Values
or Subscripts of the Array.

Types of Arrays:
One Dimensional Array
Multi Dimensional Array
Pointers

• A pointer is a variable that contains a


memory address
• Typically, a pointer contains the address
of a variable
• Addressing operator (&) calculates the
address a its operand.
&x /* expression value == address of x */

CS320 - C Programming 9
Pointers

• Declaring a pointer
int *iPtr;
float *fPtr;
– iptr is a pointer to an integer
– fptr is a pointer to a float
• initializing pointers:
int idx = 100;
int *ptr = &idx;
OR
ptr = &idx;

CS320 - C Programming 10
swap the value of two variables
Storage Classes

• Determines where the memory is


allocated and how long it remains in
existance
• storage classes:
o auto
o extern
o static
o register
CS320 - C Programming 12
auto Storage Class

• Default storage class for variables


declared in the body of a function
• Memory automatically release on exit
from control block
• Example:
main() {
int age;
auto int idx;
}

CS320 - C Programming 13
extern Storage Class

• Default storage class for variables defined


outside a function body.
• Memory allocated for the life of process
• Initialized to zero or initial value.
• Visable to functions that follow
definition
• Example:
int age;
main() {...}
CS320 - C Programming 14
static Storage Class

• Memory allocated for the life of the


process
• Initialized to zero or initial value.
• Visable to containing block
• Maintains value over invocations
• Example:
myfunc() {
static int age;
}
CS320 - C Programming 15
register Storage Class

• Compiler recommendation use CPU


register
• otherwise set to auto
• can only be part of control block
myfunc()
{
register int age;
}
CS320 - C Programming 16
Classifications of Data Types

• Built-in data types


– Fundamental data types (int, char, double,
float, void, pointer)
– Derived data types (array, string, structure)

• Programmer-defined data types


– Structure
– Union
– Enumeration
Structures
• An aggregate, user defined data type used
to represent non-simple, abstract data
• Example:
struct person {
char name[50];
char dob[11]; /* mm/dd/yyyy */
int height; /* in inches */
int weight; /* in lbs. */
};
struct person aPerson;

CS320 - C Programming 18
Global and Local Variables
• Local
/*
/* Compute
Compute Area
Area and
and Perimeter
Perimeter of
of aa
circle
circle */*/
#include <stdio.h>
#include <stdio.h>
Variables float
float pi
pi == 3.14159;
3.14159; /* /* Global
Global */
*/
– These variables are main()
main() {{
declared inside some float
floatrad;
rad;/*
/* Local
Local */
*/
functions.
printf(
printf( “Enter
“Enter the
the radius
radius ““ );
– Life time of a local );
scanf(“%f” , &rad);
scanf(“%f” , &rad);
variable is the entire
execution period of the if
if (( rad
rad >> 0.0
0.0 )) {{
function in which it is float
float area
area == pi
pi ** rad
rad ** rad;
rad;
defined. float peri = 2 * pi *
float peri = 2 * pi * rad; rad;
– Cannot be accessed by any
printf(
printf( “Area
“Area == %f\n”
%f\n” ,, area
area );
);
other function. printf( “Peri = %f\n” , peri );
printf( “Peri = %f\n” , peri );
– In general variables }}
declared inside a block else
else
are accessible only in printf(
printf( “Negative
“Negative radius\n”);
radius\n”);
that block.
printf(
printf( “Area
“Area == %f\n”
%f\n” ,, area
area );
);
}}
Global and Local Variables
• Global
/*
/* Compute
Compute Area
Area and
and Perimeter
Perimeter of
of aa
circle
circle */*/
#include <stdio.h>
#include <stdio.h>
Variables float
float pi
pi == 3.14159;
3.14159; /* /* Global
Global */
*/
– These variables are main()
main() {{
declared outside all float
floatrad;
rad;/*
/* Local
Local */
*/
functions.
printf(
printf( “Enter
“Enter the
the radius
radius ““ );
– Life time of a global );
scanf(“%f” , &rad);
scanf(“%f” , &rad);
variable is the entire
execution period of the if
if (( rad
rad >> 0.0
0.0 )) {{
program. float
float area
area == pi
pi ** rad
rad ** rad;
rad;
– Can be accessed by any float peri = 2 * pi *
float peri = 2 * pi * rad; rad;
function defined below
printf(
printf( “Area
“Area == %f\n”
%f\n” ,, area
area );
);
the declaration, in a printf( “Peri = %f\n” , peri );
file. printf( “Peri = %f\n” , peri );
}}
else
else
printf(
printf( “Negative
“Negative radius\n”);
radius\n”);
printf(
printf( “Area
“Area == %f\n”
%f\n” ,, area
area );
);
}}
An Overview of C++
Introduction
• C++ is the C programmer’s answer to Object-
Oriented Programming (OOP).
• C++ is an enhanced version of the C
language.
• C++ adds support for OOP without
sacrificing any of C’s power, or flexibility.
• C++ was invented in 1979 by Bjarne
Stroustrup at Bell Laboratories in Murray
Hill, New Jersey, USA.
22
What is OOP?
• OOP is a powerful way to approach the task
of programming.
• OOP encourages developers to decompose a
problem into its constituent parts.
• Each component becomes a self-contained
object that contains its own instructions and
data that relate to that object.
• So, complexity is reduced and the
programmer can manage larger programs.

23
Sample of C++ program

- #include <iostream.h>

int main()
{
/* program code */
return 0;
}

24
Classes: A First Look

• General syntax -

class class-name
{
// private functions and variables
public:
// public functions and variables
}object-list (optional);

25
Constructors

• Every object we create will require some sort


of initialization.
• A class’s constructor is automatically called
by the compiler each time an object of that
class is created.
• A constructor function has the same name
as the class and has no return type.
• There is no explicit way to call the
constructor.
26
Destructors

• The complement of a constructor is the


destructor.
• This function is automatically called by the
compiler when an object is destroyed.
• The name of a destructor is the name of its
class, preceded by a ~.
• There is explicit way to call the destructor
but highly discouraged.
27
C++ Program
#include<iostream.h>
#include<conio.h>
  class programming
{
private:
int variable;
  public:
  void input_value()
{ cout << "In function input_value, Enter an integer\n"; cin >> variable; }  
void output_value()
{ cout << "Variable entered is "; cout << variable << "\n"; }
};  
main()
{
programming object;
 object.input_value();
object.output_value();
  //object.variable; Will produce an error because variable is private  
return 0;
}
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy