Advanced C Concepts and Programming: First Edition
By Gayatri
3/5
()
About this ebook
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
Related to Advanced C Concepts and Programming
Related ebooks
Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Numerical Computation Using C Rating: 0 out of 5 stars0 ratingsLearning Boost C++ Libraries Rating: 0 out of 5 stars0 ratingsMastering C Pointers: Tools for Programming Power Rating: 2 out of 5 stars2/5ARM 64-Bit Assembly Language Rating: 4 out of 5 stars4/5Mastering C# and .NET Framework Rating: 5 out of 5 stars5/5Linux Kernel A Complete Guide - 2021 Edition Rating: 0 out of 5 stars0 ratingsAdvanced C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsLinux Kernel Development A Complete Guide - 2020 Edition Rating: 0 out of 5 stars0 ratingsARM Microcontrollers Programming for Embedded Systems Rating: 5 out of 5 stars5/5Modern C++ Programming Cookbook Rating: 5 out of 5 stars5/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Programming Microcontrollers in C Rating: 5 out of 5 stars5/5Assembly Language Coding in Color: ARM and NEON Rating: 0 out of 5 stars0 ratingsAssembly Language Step-by-Step: Programming with Linux Rating: 3 out of 5 stars3/5Data Structures & Algorithms Interview Questions You'll Most Likely Be Asked Rating: 1 out of 5 stars1/5Thinking In C# Programming. Rating: 0 out of 5 stars0 ratingsData Structures and Algorithm Analysis in C++, Third Edition Rating: 5 out of 5 stars5/5Java: Best Practices to Programming Code with Java Rating: 0 out of 5 stars0 ratingsC++: A Beginner's Guide, Second Edition Rating: 0 out of 5 stars0 ratingsEssential Algorithms: A Practical Approach to Computer Algorithms Using Python and C# Rating: 5 out of 5 stars5/5Assembly language The Ultimate Step-By-Step Guide Rating: 0 out of 5 stars0 ratingsC++ Programming Language Rating: 0 out of 5 stars0 ratingsProgramming Problems: A Primer for The Technical Interview Rating: 4 out of 5 stars4/5Software Development with C++: Maximizing Reuse with Object Technology Rating: 0 out of 5 stars0 ratingsC Programming Language The Beginner’s Guide Rating: 0 out of 5 stars0 ratingsThe C++ Workshop: Learn to write clean, maintainable code in C++ and advance your career in software engineering Rating: 0 out of 5 stars0 ratingsC++ Functions and tutorial Rating: 0 out of 5 stars0 ratingsComputer Programming In C Language Rating: 4 out of 5 stars4/5Lisp Programming Language Rating: 0 out of 5 stars0 ratings
Programming For You
Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsPython: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsSQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5C++ Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsSQL Guide for Microsoft Access: SQL Basics, Fundamental & Queries Exercise Rating: 5 out of 5 stars5/5
Reviews for Advanced C Concepts and Programming
1 rating1 review
- Rating: 3 out of 5 stars3/5Covers an overview part of C, good for beginnners looking to expand their C knowledge
Book preview
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