Saturday, June 17, 2023

C++ Introduction

 

   C++

Introduction

C++ is a general purpose, case-sensitive, free-form programming language that supports object-oriented, procedural and generic programming.

C++ is a middle-level language, as it encapsulates both high and low level language features.

C++ history

C++ programming language was developed in 1980 by Bjarne Stroustrup at bell laboratories of AT&T (American Telephone & Telegraph), located in U.S.A.

Bjarne Stroustrup is known as the founder of C++ language.


C++ Features

1.     Simple

2.     Object-Oriented

3.     Reusability

4.     Memory Management

5.     Extensible

Usage of C++

By the help of C++ programming language, we can develop different types of secured and robust applications:

  • Window application
  • Client-Server application
  • Device drivers
  • Embedded firmware etc

s.no.

C

C++

1)

C follows the structure or procedural oriented language.

C++ object oriented language.

2)

Data is less secured in C.

In C++, Data is more secured.

3)

C follows the top-down approach.

C++ follows the bottom-up approach.

4)

C does not support function overloading.

C++ supports function overloading.

5)

In C, scanf() and printf() are mainly used for input/output.

C++ mainly uses stream cin and cout to perform input and output operations.

6)

Operator overloading is not possible in C.

Operator overloading is possible in C++.

7)

C programs are divided into procedures

C++ programs are divided into functions and classes.

8)

C does not support the inheritance.

C++ supports inheritance.

9)

#include<stdio.h>

Std -standard

i -input

o-output

input - scanf
output- printf
 

 

 

 

 

 

 

#include<iostream.h>

i-input

o-output


stream

input - cin

output - cout

10)

#include<conio.h>

Console input output

Getch

clrscr

#include<conio.h>

Console input output

Getch

clrscr

11)

main()

{

Program;

}

Void main()

{

Program;

}

12)

Sample program

#include<stdio.h>

#include<conio.h>

main()

{

clrscr();

printf("hi hello\n");

printf("welcome to programtechie");

getch();

}

Sample program

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<"hi hello\n";

cout<<"welcome to programtechie"<<endl;

getch();

}

13)

No OOPs concept

OOPS -object oriented programming structure

Inheritance - generation

Abstraction - data hiding

Encapsulation - Data binding

Polymorphism - Multi task

Object - collections of data

Class - collections of object

C++ Variable

value storage

datatype variable_name=value;   

int x=5,b=10;  //declaring 2 variable of integer type    

float f=30.8;    

char c='A';    

Rules for defining variables

A variable can have alphabets, digits and underscore.

A variable name can start with alphabet and underscore only. It can't start with digit.

No white space is allowed within variable name.

A variable name must not be any reserved word or keyword e.g. char, float etc.

Valid variable names:

int a;    

int _ab;    

int a30;    

Invalid variable names:

int 4;    

int x y;    

int double;

 

 

Runtime program

#include <iostream.h> 

#include <conio.h>

void main()  

{  

    int x, y;    // variable declaration.  

    clrscr();

    cout<<"Enter the values of x and y";  

    cin>>x>>y;  

    cout<<"Value of x"<<x<<endl;

    cout <<"Value of y is :"<<y; 

    getch();

output

Enter the values of x and y

53

value of x=5

value of y=3

C++ Data Types

Types

Data Types

 

Basic Data Type

int, char, float, double, etc

 

Derived Data Type

array, pointer, etc

 

Enumeration Data Type

enum

 

User Defined Data Type

structure

 

Data Types

Memory Size

Range

 

char

1 byte

-128 to 127

%c

signed char

1 byte

-128 to 127

 

unsigned char

1 byte

0 to 127

 

short

2 byte

-32,768 to 32,767

 

signed short

2 byte

-32,768 to 32,767

 

unsigned short

2 byte

0 to 32,767

 

int

2 byte

-32,768 to 32,767

%d

signed int

2 byte

-32,768 to 32,767

 

unsigned int

2 byte

0 to 32,767

 

short int

2 byte

-32,768 to 32,767

 

signed short int

2 byte

-32,768 to 32,767

 

unsigned short int

2 byte

0 to 32,767

 

long int

4 byte

%ld

signed long int

4 byte

 

unsigned long int

4 byte

 

float

4 byte

%f

double

8 byte

%lf  or %ld

long double

10 byte

 

C++ Keywords

auto

break

case

char

const

continue

default

do

double

else

enum

extern

float

for

goto

if

int

long

register

return

short

signed

sizeof

static

struct

switch

typedef

union

unsigned

void

volatile

while

 

0 comments:

Post a Comment