1 / 21

Data Structure and c Part-5

Data Structure and c Part-5. Mean. An array Symbol [] An array is a group of related data items that stare a common name. Example:- Salary [10]: . Salary 1 [10]; Salary 2[15]; Salary 3[20]; Salary 4[25].

kaleb
Download Presentation

Data Structure and c Part-5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structure and cPart-5

  2. Mean An array Symbol [] An array is a group of related data items that stare a common name. Example:- • Salary [10]:

  3. Salary 1 [10]; Salary 2[15]; Salary 3[20]; Salary 4[25]

  4. Initializing array It have to specify the index of the subscript with the square brackets. Syntax; Storage class data type array [size] = {value1, value2, value3} Example:- Int num [5] = {3,4,6,7,10}

  5. Unsized Array The compiler will count the number of initialize and substitute that number of the size of the array Example:- Int even [ ] = {2,4,6,8,10} Int Odd [ ] = {1,3,5,7,9}

  6. Three several types of Arrays

  7. One-Dimensional array 1-D Example:- One dimensional array int * [6]; Syntax; data type array name [size];

  8. Two dimensional arrays2-D • Two dimensional arrays is also called matrix • It has two subscripts Syntax; Storage class data type array [s1] [s2]; Example:- Int X [i]; Int Y [i]; OR int a [2] [2];

  9. Array of String It string is defined as a null terminated character array. An array should be defined with an additional byte for holding this null character. Syntax; Char array name [size]; Example:- Char name [6] = “india” ;

  10. STORAGE CLASSES • Storage Classes define a variable one needs to mention not only its ‘type’. • But also its ‘storage class’ Storage class refers to the permanence of a variable.

  11. Types of Storage Class

  12. Automatic storage class • Storage - Memory • Default initial value - Garbage value • Scope - Local to the block in which the variable isdefined • Life - Till the control remains within the block in which it is defined The keyword for this storage class is auto.

  13. Example of Code Program Example: main ( ) { increment ( ); increment ( ); increment ( ); getch ( ); } Increment ( ); { auto int i = 1; print (“%d\n”,i); i = i+1; } The output of the program is: 1 1 1

  14. Register storage class • Storage - CPU registers. • Default initial value - Garbage value. • Scope - Local to the block in which the variable is defined. • Life - Till the control remains within the block in it isdefined.

  15. Example of Code Program Example: main ( ) { register int i; for (i=1;<=10;i++) print (“%d\t”,i); getch ( ); } The output is 1 2 3 4 5 6 7 8 9 10

  16. Static storage class • A storage class with persistent duration is static. • A static variable declared inside a function retains its value after the function terminates. • Storage -Memory • Default initial value -Zero • Scope -Local to the block in which the variable is defined • Life -Value of the variable persists between differentFunction calls.

  17. Example of Code Program Example: # include <stdio.h> main ( ) { increment ( ); increment ( ); increment ( ); getch ( ); } increment ( ); { static int i = 1; print (“%d\n”,i); i = i+1; }

  18. External storage class The features of a variable whose storage class has been defined as extern are as follows: • Storage -Memory • Default initial value -Zero • Scope -Global • Life -As long as the program execution doesn’tcome to an end

  19. Example of Code Program Example: int main ( ) { extern int z; int i; ……… ……… return 0 ; }

  20. FUNCTIONS of TYPES Functions are the building blocks of the C programming language. The most important of the C functions is the main( ) function. Some of the other functions are given below:-

  21. printf( ) • scanf( ) • getchar( ) • getch( )

More Related