Dive Into Sea of C
By M Ashok
()
About this ebook
Dive into the world of C programming with our accessible guide, where every concept is demystified in simple English terms. This book goes beyond theory, offering hands-on learning with clear and concise code examples for each topic. From foundational principles to advanced techniques, readers progress seamlessly, gaining confidence through practical exercises. Real-world applications are woven into the fabric of the book, connecting theory to practice. Whether you're a beginner or seeking to enhance your skills, this resource equips you with the tools to write efficient and robust code. Unlock the power of C programming with clarity, simplicity, and a focus on real-world applicability in every chapter.
Related to Dive Into Sea of C
Related ebooks
"C Programming for Beginners: A Step-by-Step Guide" Rating: 0 out of 5 stars0 ratingsCoding In C Decoded: Decoded, #1 Rating: 0 out of 5 stars0 ratingsC Programmin Language Rating: 0 out of 5 stars0 ratingsProgramming In ‘C’ Rating: 0 out of 5 stars0 ratingsThe 1 Page Python Book Rating: 2 out of 5 stars2/5Coding for beginners The basic syntax and structure of coding Rating: 0 out of 5 stars0 ratingsC language Programming: Simple, Short, and Straightforward Way of Learning C Programming Rating: 3 out of 5 stars3/5Learn C Programming in 24 Hours Rating: 0 out of 5 stars0 ratingsC Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Programming with Python Rating: 0 out of 5 stars0 ratingsUpdate to Modern C++ Rating: 0 out of 5 stars0 ratingsBasic Language Rating: 0 out of 5 stars0 ratingsPractical Numerical C Programming: Finance, Engineering, and Physics Applications Rating: 0 out of 5 stars0 ratingsProblem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5C++ Programming Language Rating: 0 out of 5 stars0 ratingsLearn to Code with C: Program with the world's most popular language on your Raspberry Pi Rating: 0 out of 5 stars0 ratingsComputer Practices Using C++ Rating: 0 out of 5 stars0 ratingsC Programming Wizardry: From Zero to Hero in 10 Days: Programming Prodigy: From Novice to Virtuoso in 10 Days Rating: 0 out of 5 stars0 ratingsWindows Batch File Programming Rating: 2 out of 5 stars2/5Introduction to C Programming, a Practical Approach Rating: 0 out of 5 stars0 ratingsPython for Beginners: An Introduction to Learn Python Programming with Tutorials and Hands-On Examples Rating: 4 out of 5 stars4/5UNIX Shell Programming Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsThe Dev-c++ Reference Manual Rating: 5 out of 5 stars5/5Understanding Python: Beginner's Guide to Programming Rating: 0 out of 5 stars0 ratingsC# Programming Illustrated Guide For Beginners & Intermediates: The Future Is Here! Learning By Doing Approach Rating: 0 out of 5 stars0 ratingsComputer Engineering Laboratory Solution Primer Rating: 0 out of 5 stars0 ratingsModern C Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library Rating: 0 out of 5 stars0 ratingsC Programming Concepts Rating: 0 out of 5 stars0 ratingsC# For Beginners: An Introduction to C# Programming with Tutorials and Hands-On Examples Rating: 0 out of 5 stars0 ratings
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/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 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratings
Reviews for Dive Into Sea of C
0 ratings0 reviews
Book preview
Dive Into Sea of C - M Ashok
Preface
Four decades after its introduction, C remains the most popular and widely used programming language. Its versatility can be attributed to the fact that operating systems such as Windows and Unix, as well as many high-level languages, inherit C's control structures and other basic features. Python programming language is written in C, and most used libraries in Machine learning and Deep learning, like Tensorflow, are written in C. Programmers around the world use the C language for its incredible efficiency. In some cases, C code can run as fast as code written in assembly language. C code is versatile, extensible, and portable. Therefore, for most students, C remains the first step towards learning programming skills.
Table of Contents
First C Program—1
Tokens—5
Operators,Control and Looping statements—30
Functions—82
Arrays—92
Strings—118
Pointers—143
Structures, Unions and Enums—174
1. Understanding the First C Program:
Output:
After executing the above 5-line C program in any IDE or code editor, we get Hello World!!! as output. Let’s understand our first program by breaking it into three simpler parts.
The above line simply says to include the file named stdio.h into the program. Files ending with. h extensions are called header files. Why should a C program include header files? In the C language, there is flexibility for programmers to include already written or predefined functionality into the program. In the above program, the printf() function is used. The functionality or working of the printf() function is already written in the stdio.h file, which is to print sentences enclosed in double quotes as output. The sections that follow provide answers to the following queries: Why is printf() referred to as a function? What is a function? How does a function operate?
Every header file has some predefined functions in it. To use those predefined functions, the corresponding header file must be included. Below are the most used header files in the C language:
➢ stdio.h – It has all the predefined input and output functions, such as printf(), scanf(), gets(), puts(), etc.
➢ math.h – It has all the predefined mathematical functions such as ceil(), sqrt(), pow(), exp(), etc.
➢ string.h – It has all the predefined string manipulation functions such as strncpy(), strncat(), strncmp(), strchr(), etc. (string is nothing but any English statement enclosed in double quotes like I am learning
, My mobile is not working
, I have a laptop
etc)
In the C language, there are two types of functions, one is predefined in header files, and the other is user-defined functions. Let’s understand the predefined functions here.
Predefined functions make programmer's lives easy. Every predefined function takes zero or more inputs with brackets enclosed, just like the printf function took Hello World!
as input in our program. Here, printf works by taking the statement enclosed in the brackets as input and printing that statement onto the output screen. Below are a few examples of predefined functions:
➢ printf(Any English statement
) – printf() function takes an English statement as input and prints that English statement as output.
Examples:
printf(C language
) prints C language
as output,
printf(welcome to programming
) prints welcome to programming
as output.
➢ sqrt(x) – sqrt() function takes a number as input and gives the square root of that number as output.
Examples:
sqrt(25)=5.0
sqrt(4)=2.0
➢ pow(a,b) – pow() function takes two numbers (like a and b) as input and gives a to the power of b as the output.
Examples:
pow(4,2)=16.0
pow(10,2)=100.0
main is the most important function in the C language. Above is one of the simplest ways of writing the main function and In the coming chapters, we will learn about other variations of the main function.The execution of any C program starts with main function only, and any number of statements or lines can be included or written in between opening and closing flower brackets or curly braces. (Every line in the C program can be called a statement.) At the end of every statement, a semicolon (;) is used to indicate the end of the line or statement.
In our above program, only 1 statement (i.e. printf(Hello World!!!
); ) is included or written in between the opening and closing flower brackets or braces of the main function, so execution starts and ends with the first line. If a main function has 5 lines, then execution starts with the 1st line and continues sequentially with the 2nd, 3rd, 4th, and finally the 5th line. Execution stops after the 5th line is executed. The main function gives the direction for execution of a C program, that's why it is called the most important function in C.
Output:
Compiler:
It is system software that executes the C program. User-written programs or codes are translated by the compiler into a different kind of program or code that the operating system can understand. The compiler first checks for the main function in the program and starts execution from the first line of the main function.
2. Tokens :
Tokens in the C language are the minor elements or the building blocks used to construct, write, or develop a C program. It is the basic component of a C program. These tokens in C are meaningful to the compiler. The compiler breaks a program into tokens and proceeds with further execution.
There are 5 tokens in the C language which are keywords, special symbols, constants, identifiers, and operators.
Keywords:
In our first C program, there are some words like include, main, printf, and void. These words have specific functionality associated with them, and based on that functionality, the compiler is programmed to execute the C program. By convention, all keywords must be written in lowercase. Below is the functionality of the keywords used in our first program.
➢ main – compiler understands that execution of the program should start from here.
➢ include – when any header file is included in a program by using the include word (like #include
➢ printf – it is a predefined function whose functionality is to print strings to the output screen or console.
Following is a list of all 32 keywords in the C language:
Special symbols:
Special symbols define the syntax and organization of code, and their proper use is crucial for writing syntactically correct programs. Following are the special symbols used in the C language.
➢ Semicolon (;)
➢ Parentheses (())
➢ Braces ({ })
➢ Brackets ([ ])
➢ Comma (,)
➢ Ampersand (&)
➢ Asterisk Symbol(*)
Variables and Data Types:
The aim of any program is to convert given inputs (or input data) into required or desired outputs( or output data). In this process, the program might use some temporary data or values as well.
To use data or value in a program, two things must be mentioned: first, the type of data (referred to as DataType) and, second, the variable. Data is typically stored in memory locations, to which a variable is attached. A variable is simply a name for a memory location in which data is stored.
Let’s store temperature data in a variable,
Here, int is the data type, which indicates that the data that is stored is an integer value; temperature is the variable; and 35 is the value or data.
Let’s store height,
Here, float is the data type, which indicates that the data that is stored is a decimal value, h is the variable, and 5.9 is the value or data.
Any datatype in C has three important properties:
➢ Range: It indicates the interval of values a data type can hold.
➢ Size: It depends on the compiler, which