An introduction to C

Unlocking the Power of Programming

An Introduction to C

Welcome to the world of programming! Whether you're a curious novice embarking on your coding journey or a seasoned developer exploring new horizons, one language stands out as a timeless cornerstone of computer science: C.

C is more than just a programming language; it's a fundamental building block that has shaped the digital landscape since its inception in the early 1970s. Developed by Dennis Ritchie at Bell Labs, C was designed to provide a powerful yet flexible platform for software development.



Why Learn C?

!!!

In a world dominated by high-level languages like Python and Java, you might wonder why bother learning C. The answer lies in its timeless principles and enduring relevance. Understanding C not only lays a solid foundation for mastering other languages but also fosters a deeper understanding of computer architecture and programming fundamentals.



LETS START OUR JOURNEY


Variables

  • Programming language enable you to assign symbolic names, known as variable names, for storing program computations and results.

  • A variable name can be chosen by you in a meaningful way to reflect the type of value that is to be stored in that variable.

  • Variables can be used to store integers, floating point numbers, characters, strings and even pointers to locations inside the computer’s memory.

  • Before using a variable in C, you need to declare its type

  • The rules for forming variable names
    • must begin with a letter or underscore
    • cannot use special symbols/ characters
    • can be followed by any combination of letters (upper or lowercase), underscores, or the digits 0–9.

  • for an example : sum, Total, i, _add
  • upper and lowercase letters are distinct in C.

DATA TYPES







Data types are fundamental building blocks in programming languages, including C. They define the type of data that a variable can hold and the operations that can be performed on that data. In C, data types specify the size and format of values stored in memory, allowing programmers to allocate memory efficiently and manipulate data effectively. Let's explore the various data types available in C programming.


1. Integer Data Types
  • int : The most commonly used integer data type in C. It typically occupies 4 bytes of memory and can hold whole numbers within a specific range.
  • short int: A smaller version of the int data type, occupying 2 bytes of memory. It can store smaller integer values but has a more limited range compared to int.
  • long int: A larger version of the int data type, typically occupying 4 or 8 bytes of memory depending on the system architecture. It can store larger integer values than int.

2. Floating-Point Data Types

  • float: Used to store single-precision floating-point numbers, which can represent decimal values with moderate precision. It typically occupies 4 bytes of memory.
  • double: Used to store double-precision floating-point numbers, providing higher precision compared to float. It typically occupies 8 bytes of memory.

3. Derived Data Types


  • Array: A collection of elements of the same data type arranged in contiguous memory locations.
  • Pointer: A special type used to store memory addresses. Pointers allow indirect access to memory and are commonly used for dynamic memory allocation and manipulation of data structures.
  • typedef: A keyword used to create custom data type aliases or typedef names. Typedef allows programmers to define new names for existing data types, enhancing code clarity and abstraction.


4. User defined Data Types


  • enum : A user-defined data type used to define a set of named constants, known as enumerators. Enums provide a way to create symbolic names for integer values, improving code readability and maintainability.
  • Structure: A user-defined data type that groups together variables of different data types under a single name. Structures allow for the creation of complex data structures.


Constants



- In C, any number, single character, or character string is known as a constant.
- E.g. the number 60 represents a constant integer value.
There are five different types of constants
  • Integer constants
  • Floating point constants
  • Character constants
  • Character String Constants
  • Enumeration Constants

- Integer Constants: Integer constants are whole numbers without a decimal point. They can be represented in various formats, such as decimal , octal , or hexadecimal.
  • - Decimal Constant: Example - int num = 10;
  • - Octal Constant: Example - int octalNum = 012; (preceded by '0')
  • - Hexadecimal Constant: Example - int hexNum = 0x1A; (preceded by '0x' or '0X')


What are Keywords?




Keywords, also known as reserved words, are a set of predefined identifiers in C programming that convey specific meanings and functionalities to the compiler. These words cannot be used as identifiers such as variable names or function names.
  

Some commonly used keywords are listed below👇





What are Format Specifiers?






Format specifiers, also known as format strings or conversion specifiers, are placeholders used within the printf() and scanf() functions to indicate the type and format of data being processed. They provide a standardized way to represent and manipulate various data types, such as integers, floating-point numbers, characters, and strings.


Some commonly used format specifiers are listed below👇






Designed by : M.I AFTHAL AHAMAD (ICT/2022/105)





Post a Comment

0 Comments