Escolar Documentos
Profissional Documentos
Cultura Documentos
Overview of C
C is developed by Dennis Ritchie
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:
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:
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:
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
Pointers
Declaring a pointer
int *iPtr; float *fPtr;
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
}
CS320 - C Programming 13
}
CS320 - C Programming 15
Structures
An aggregate, user defined data type used to represent non-simple, abstract data Example:
struct person { char name[50]; char dob[11]; int height; int weight; }; struct person aPerson;
CS320 - C Programming
18
/* Local */
printf( Enter the radius ); scanf(%f , &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( Area = %f\n , area ); printf( Peri = %f\n , peri ); } else printf( Negative radius\n); printf( Area = %f\n , area ); }
/* Local */
printf( Enter the radius ); scanf(%f , &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( Area = %f\n , area ); printf( Peri = %f\n , peri ); } else printf( Negative radius\n); printf( Area = %f\n , area ); }
An Overview of C++
Introduction
C++ is the C programmers answer to ObjectOriented Programming (OOP). C++ is an enhanced version of the C language. C++ adds support for OOP without sacrificing any of Cs 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
Constructors
Every object we create will require some sort of initialization. A classs 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