Găsiți următorul dvs. carte preferat

Deveniți un membru astăzi și citiți gratuit pentru 30 zile
Advanced C Concepts and Programming: First Edition

Advanced C Concepts and Programming: First Edition

Citiți previzualizarea

Advanced C Concepts and Programming: First Edition

Lungime:
346 pages
2 hours
Lansat:
Apr 26, 2016
ISBN:
9781456619732
Format:
Carte

Descriere

This book is for readers of IT Fields.

Key features of this book include:

Used systematic approach throughout the book

Programming advances in C without requiring prior knowledge in C language

Simple language has been adopted to make the topics easy and clear to the readers

This book covers virtually most of the advanced features of Advanced C Programming including:

Multidimensional Arrays

Pointers

Functions

Structures

Union

Preprocessing

File Management

Topics have been covered with more than 100 illustrations and tested C programs with screen display

Enough examples have been used to explain various advanced concepts effectively.

Provides exercises, review questions and exercises as the end of each chapter equipped with more than 200 questions in various patterns and more than 120 programming exercises
Lansat:
Apr 26, 2016
ISBN:
9781456619732
Format:
Carte

Despre autor


Legat de Advanced C Concepts and Programming

Cărți conex
Articole conexe

Previzualizare carte

Advanced C Concepts and Programming - Gayatri

Advanced C Concepts and Programming

By

Gayatri

B.E. CSE, M.E, GTU

First Edition: 2013

Key Talks

Used systematic approach throughout the book

Programming advances in C without requiring prior knowledge in C language

Simple language has been adopted to make the topics easy and clear to the readers

This book covers virtually most of the advanced features of Advanced C Programming including:

§  Multidimensional Arrays

§  Pointers

§  Functions

§  Structures

§  Union

§  Preprocessing

§  File Management

Topics have been covered with more than 100 illustrations and tested C programs with screen display

Enough examples have been used to explain various advanced concepts effectively. 

Provides exercises, review questions and exercises as the end of each chapter equipped with more than 200 questions in various patterns and more than 120 programming exercises

Copyright

Advanced C: Concepts and Programming

Copyright © 2013 by the Author

All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.

Warning and Disclaimer

Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.

Contents

UNIT 1 Advanced Data structure: Array

One-Dimensional Array and its Operations

Two-Dimensional Array and its Operations

Three or Multi-Dimensional Arrays

sscanf() and sprintf() Functions

Drawbacks of Linear Arrays

Exercise

UNIT 2 Strings and Standard Functions

Introduction of String

Declaration and Initialization of String

Displaying Strings with Different Formats

Standard String Functions

Various String handling functions’ programs

Exercise

UNIT 3 Pointers

Introduction to Pointers

Features of Pointers

Benefits of using Pointer

Declaring a Pointer

Initializing a pointer

The Address-of Operator (&)

Difference between pointer and array

Pointer Arithmetic

Void Pointers

Pointers and Arrays

Difference between pointer and array

Array of Pointers

Static memory allocation

Dynamic memory allocation

Static memory allocation Vs Dynamic memory allocation

Pointers to Pointers (Pointers Chain)

Advantages of pointer

Pointer Drawbacks

Dangers of pointers

Exercise

UNIT 4 Functions

Basics of a Function: Declaring and defining function

Why use Functions?

How a Function Works?

Communication between functions

Actual argument and Formal argument

Parameter passing

Returning values

Categories of functions

Passing Function as an Argument

Recursion

Advantages of Recursion

Disadvantages of Recursion

Exercise

UNIT 5 Preprocessor Directives

Introduction to Preprocessor

Why use Preprocessor (Macro)?

Conditional Preprocessor Directives

Unconditional Preprocessor Directives

Miscellaneous Preprocessor Directives

Predefined macros in ANSI C

Standard I/O Predefined Streams in stdio.h

Predefined macros in ctype.h

Macro Vs Function

Exercise

UNIT 6 Structure and Union

Introduction and Features of Structures

Declaring structure

Structure Initialization

Array of Structures

Nested structure

Array Vs Structure

Pointer and Structure

Pointer to Structure

typedef

Enumerated Data Type

Union

Union of Structures

Exercise

UNIT 7 Files

Introduction to file and stream

Types of files

Need of file handling

The Basics of Disk File I/O

File Operations

Basic File Operations on Text Files

Binary file operations

Opening a File

Reading a File

Writing to a File

Closing a File

File Functions

Command Line Arguments

Exercise

UNIT 1 Advanced Data structure: Array

Array is a linear data structure that stores the same types of data in contiguous memory locations. Arrays are best used to store data in contiguous memory locations. However an array can have a definite size of data. The maximum size of an array must be set when declaring the array. An array can be defined as below:

int myarray[5];

Diagrammatically myarray can be shown as below:

Some information about the above array is:

1)    The Name of the array is myarray.

2)    This is an integer array

3)    The size of the array is 5

4)    The Base address of the array is 2000H

5)    One element takes 2 bytes in memory.

6)    0,1,2,3,4 are the indexes of the array

7)    99, 13,77,567,9 are elements of the array.

8)    You can say 77 is an array element at the 2nd position of the array.

Notation to fetch array elements is as below:

myarray[2]=77

If you need to find the memory location of the 20th element in the above array then you can get that using the following formula:

Base location + (Memory size of element * (Element Position -1))

In the above case:

1)    Base memory location = 2000H

2)    Size of element = 16 Bits (=2 Bytes)

3)     Element position = 20

Memory location of 20th element = 2000 + (16 * (20-1)) = 2000 + 16 *19 = 2304H

One-Dimensional Array and its Operations

On an array, usually the following native operations can be performed:

1)    Traversing an array

2)    Search an element in array

3)    Insert an element at given position in array

4)    Delete and element from a given position in array

5)    Reverse an array

6)    Sorting the array

Traversing an Array

Traversing an array means iterate through each element of the array once and perform some operations on each element. Process to traverse an array:

In the above pseudo code K is a variable, A is an array and N is an upper limit of the array. In C a function to traverse an array and print all the elements can be as below:

#include

#include

int  traverse(int *myarray)

{

int i;

for(i=0;i<5;i++)

{

printf(%d\n,myarray[i]);

}

return 0;

}

void main()

{

  int myarray[5];

  clrscr();

  myarray[0]=9;

  myarray[4]=99;

  traverse(myarray);

  getch();

}

You should get output as below:

You can see in the output that for the 2nd, 3rd and 4th position the elements have some garbage value because we did not assign any values to these positions in the array.

Insert an element in Array

You can insert an element to a given position in array using the following algorithm. Let us say:

1)    K: position to insert element

2)    Element: element to insert

3)    N : Size of the array

4)     A : Name of the array

Process to insert an element into an array at given position:

In C the function to insert an element in a given position in array can be written as below:

int insertelement(int *myarray, int position, int element)

{

int i;

for(i=4;i>=position;i--)

{

myarray[i]=myarray[i-1];

}

myarray[i]=element;

return 0;

}

And in the main function you can call this function as below:

#include

#include

#define MAX 5

int  traverse(int *myarray)

{

int i;

for(i=0;i<5;i++)

{

printf(%d\n,myarray[i]);

}

return 0;

}

int insertelement(int *myarray, int position, int element)

{

int i;

for(i=4;i>=position;i--)

{

myarray[i]=myarray[i-1];

}

myarray[i]=element;

return 0;

}

void main()

{

  int myarray[5];

  clrscr();

  myarray[0]=9;

  myarray[4]=99;

  printf(Array elements before Insert\n);

  traverse(myarray);

  insertelement(myarray,2,50);

  printf(Array elements before Insert\n);

  traverse(myarray);

 getch();

}

When you run the above program you will find 99 has been inserted at the 2nd position as below:

You will notice all the elements after the 2nd position have been shifted by one place.

Graphical representation of insert operation

Delete an element from Array

You can delete an element at a given position in an array by using the following algorithm. Let us say:

1)    K: position to delete element

2)    N : Size of the array

3)    A : Name of the array

Process to delete an element from an array at given position:

In C you can write a function to delete an element from a specified position as below:

int deleteelement(int *myarray,int position)

{

         int i;

         for(i=position; i<5; i++)

         {

                 myarray[i-1]=myarray[i];

         }

         myarray[i-1]=0;

         return 0; 

}

And in the main function you can call this function as below:

#include

#include

#define MAX 5

int  traverse(int *myarray)

{

int i;

for(i=0;i<5;i++)

{

printf(%d\n,myarray[i]);

}

return 0;

}

int deleteelement(int *myarray,int position)

{

         int i;

   for(i=position; i<5; i++)

         {

                 myarray[i-1]=myarray[i];

         }

         myarray[i-1]=0;

         return 0;

}

void main()

{

  int myarray[5];

  clrscr();

  myarray[0]=9;

  myarray[4]=99;

  printf(Array elements before Delete\n);

  traverse(myarray);

  deleteelement(myarray,2);

  printf(Array elements after Delete\n);

  traverse(myarray);

 getch();

}

Graphical representation of delete operation

Search an element into Array

There are two types of searches you can perform on an array:

1)    Linear Search

2)    Binary Search

Binary search is out of the scope of this course

Ați ajuns la sfârșitul acestei previzualizări. Înscrieți-vă pentru a citi mai multe!
Pagina 1 din 1

Recenzii

Ce părere au oamenii despre Advanced C Concepts and Programming

0
0 evaluări / 0 Recenzii
Ce părere aveți?
Evaluare: 0 din 5 stele

Recenziile cititorilor