Posts

Introduction to C programming

Image
Introduction to the C Programming Language C is a general-purpose, high-level programming language originally developed by Dennis M. Ritchie at Bell Labs to build the UNIX operating system . C was first implemented in 1972 on the DEC PDP-11 computer. Key Features of C Language Provides low-level access to memory Has a simple and small set of keywords Follows a clean and structured programming style These features make C highly suitable for: System programming Operating system development Compiler development Influence on Other Programming Languages Many modern programming languages have borrowed syntax and features from C, either directly or indirectly. Examples include: Java PHP JavaScript C++ is almost a superset of C , adding object-oriented programming features while retaining most of C’s functionality. Ken Thompson  (left) with  Dennis Ritchie  (right, the inventor of the C programming language) History and Standards...

Primitive and Derived Data Type

 In the C programming language, data types are essential because they tell the compiler what kind of data a variable can hold . Choosing the correct data type improves the efficiency, clarity, and correctness of your program. Data types in C are broadly categorized into two: Primitive (Basic) Data Types Derived Data Types 🟢 1. Primitive (Basic) Data Types These are the fundamental building blocks of data in C. They are built into the language and represent the most basic kinds of data. ➤ Common Primitive Data Types: Data Type Description Example int Integer values (whole numbers)      int age = 25; float Single-precision decimal values      float price = 99.5; double Double-precision decimal values      double pi = 3.14159; char Single characters      char grade = 'A'; 📝 Note: Each type uses different memory sizes and has specific ranges . For example, int typically uses 4 bytes and ranges from -...

Enumerated Data Type

Enumeration ( enum ) in C 📌 Definition Enumeration (or enum ) is a user-defined data type in C. Used to assign names to integral constants Makes programs easier to read and maintain Each symbolic name represents an integer constant Declared using the keyword enum 📌 General Syntax enum tag_name {member1, member2, member3, ..., memberN} variable1, variable2, ..., variableN; Notes: Either tag_name or variables may be omitted Both can also be present But at least one must exist 📌 Default Values of Enum Members Members are assigned integer values automatically First member → 0 Second → 1 Third → 2 And so on… 📌 Example Declaration enum week {Mon, Tue, Wed, Thu, Fri, Sat}; enum week day; OR enum week {Mon, Tue, Wed, Thu, Fri, Sat} day; 📌 Example Program (Default Values) # include <stdio.h> enum day {sunday, monday, tuesday, wednesday, thursday, friday, saturday}; int main () { enum day d = thursday...

Data Types and Qualifiers in C

Image
There are four data types in C language. They are, Types Data Types   Basic data types   int, char, float, double   Enumeration data type   enum   Derived data type   pointer, array, structure, union   Void data type   void Here we will discuss only basic data types. Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one:   Following are the examples of some very common primitive data types used in C:   char:  The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. int:  As the name suggests, an int variable is used to store an integer. float:  It is used to store decimal numbers (numbers with floating point value) with single precision. double:  It is used to store decimal numbers (numbers with floating p...

Keywords and Identifiers in C

Image
C Keywords 📌 Definition Keywords are predefined and reserved words in C programming that have special meanings to the compiler. Keywords are part of the language syntax They cannot be used as identifiers (variable names, function names, etc.) Since C is case-sensitive , all keywords must be written in lowercase 📌 Example int money; int → keyword indicating the data type integer money → variable name (identifier) Here, int tells the compiler that money is an integer variable. 📌 Number of Keywords in ANSI C ANSI C contains 32 keywords . ✔ List of ANSI C Keywords Additional Keywords in C Along with the 32 ANSI C keywords , C may support additional keywords depending on the compiler implementation . C Identifiers 📌 Definition An identifier is the name given to program elements such as: Variables Functions Structures Arrays Objects Identifiers must be unique so that each entity can be identified during program execution. ...

Escape Sequences

Character Set and Escape Sequences in C 📌 Character Set in C In the C programming language, the character set consists of 256 characters . It is broadly divided into: 1️⃣ ASCII character set 2️⃣ Extended ASCII character set Apart from these, C also includes special characters called escape characters (escape sequences) . 📌 Escape Characters (Escape Sequences) Escape sequences are special character combinations beginning with a backslash \ . They are used to represent: Non-printable characters Formatting characters Special symbols inside strings 📋 List of Escape Sequences in C Escape Sequence Meaning \a           Alarm / Beep \b           Backspace \f           Form Feed \n           New Line \r           Carriage Return \t                Horizontal Tab \v  ...

Variables and constants in C

Image
Variables and Constants in C 📌 Variables A variable is a container (storage location) used to store data. Each variable has a unique name (identifier) The name represents a memory location The value stored in a variable can change Example int playerScore = 95 ; playerScore → variable name int → data type 95 → stored value 👉 In C, variables must be declared before use . 📌 Rules for Naming Variables Can contain: Letters (A–Z, a–z) Digits (0–9) Underscore _ First character must be: Letter OR underscore _ Starting with _ is discouraged (may conflict with system names) Length: No strict limit Most compilers check only the first 31 characters C is strongly typed Variable type cannot be changed after declaration Constants / Literals in C A constant is a value that cannot be changed during program execution. Examples 1 2.5 "C programming is easy" Constants can also be defined using identifi...