History of C Programming Language
10 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What will be printed by the program in Example 1 with the static variables?

  • garbage garbage garbage
  • 0
  • 2
  • 0 0 0 0.000000(null) (correct)
  • Which storage class allows variables to hold their value between multiple function calls?

  • External
  • Register
  • Auto
  • Static (correct)
  • In C programming, which class of variable is allocated memory in the CPU registers?

  • External
  • Auto
  • Static
  • Register (correct)
  • What happens if you try to dereference a register variable in C?

    <p>It will lead to a compilation error.</p> Signup and view all the answers

    What is the default initial value of external integral type variables in C?

    <p>0 otherwise null</p> Signup and view all the answers

    Which type of variable can only be initialized globally, not within any block or method?

    <p>External</p> Signup and view all the answers

    What is the visibility of static local variables in C?

    <p>Function scope</p> Signup and view all the answers

    Which keyword is used to define a static variable in C?

    <p>statico</p> Signup and view all the answers

    What is the purpose of the 'register' keyword in C programming?

    <p>To indicate that a variable should be stored in CPU registers</p> Signup and view all the answers

    How many times can an external variable be initialized in a C program?

    <p>Once globally only</p> Signup and view all the answers

    Study Notes

    History and Development of C

    • C language was developed in 1972 by Dennis M. Ritchie at Bell Laboratories, USA.
    • The American National Standards Institute (ANSI) formed a committee in 1983 to create a standard definition of C, resulting in ANSI C.
    • C is closely associated with UNIX, with most of UNIX's code written in C, making it one of the first portable operating systems.
    • The language evolved from BCPL and earlier forms, including the B language by Ken Thompson.
    • The foundational book on C, "The C Programming Language," was published in 1978 by Brian Kernighan and Dennis Ritchie.

    Importance of C

    • C is robust with a rich set of built-in functions, data types, and operators facilitating complex program development.
    • Programs written in C are efficient due to diverse data types and operators.
    • Combines low-level capabilities similar to assembly language with the features of high-level languages.
    • Highly portable; code can be executed across different hardware architectures.
    • Supports low-level programming like bit manipulation and memory access through pointers.
    • User-friendly syntax that closely resembles English.

    Basic Structure of C Program

    • C programs follow a defined structure:
      • Documentation section
      • Preprocessor section
      • Definition section
      • Global declaration
      • Main function
      • User-defined functions

    Key Sections of a C Program

    • Documentation Section: Provides an overview of the program (name, description, etc.) using comments.
    • Preprocessor Section: Includes header files, e.g., #include <stdio.h>.
    • Define Section: Contains constants defined with #define.
    • Global Declaration: Declares global variables available throughout the program.
    • Main Function: Entry point of the program, mandatory for execution. Can be structured with local declarations, statements, and expressions.
    • User Defined Functions: Functions created as per user requirements; optional but commonly used.

    Program Execution Process

    • C program files are saved with a .c extension and compiled into an object file (.obj).
    • The linker combines object files with library functions to create an executable file (.exe).
    • The loader loads the executable into RAM for execution, managing CPU instructions through the Instruction Register and Program Counter.

    Basic C Programs Examples

    • Printing a Message:
      #include <stdio.h>
      int main() {
          printf("welcome to c programming");
      }
      
    • Addition of Two Numbers:
      #include <stdio.h>
      int main() {
          int a, b, sum;
          printf("\nEnter two no: ");
          scanf("%d %d", &a, &b);
          sum = a + b;
          printf("Sum : %d", sum);
          return 0;
      }
      
    • Interest Calculation:
      #include <stdio.h>
      int main() {
          int p, r, t, int_amt;
          printf("Input principle, Rate of interest & time:\n");
          scanf("%d%d%d", &p, &r, &t);
          int_amt = (p * r * t) / 100;
          printf("Simple interest = %d", int_amt);
          return 0;
      }
      

    C Math Functions

    • C provides mathematical functions in the <math.h> library, such as:
      • ceil(): Rounds up to the nearest integer.
      • floor(): Rounds down to the nearest integer.
      • sqrt(): Calculates the square root.
      • pow(): Raises a number to a power.
      • abs(): Returns the absolute value.

    C Tokens and Keywords

    • Tokens: Individual elements in a C program, including keywords, identifiers, constants, and operators.
    • Keywords: Reserved words with predefined meanings in C (e.g., int, return, if, while).

    Identifiers and Variable Declaration

    • Identifiers are variable names composed of letters, digits, and underscores, beginning with a letter or underscore.
    • Variables must be declared with their data types before use, in the format: data-type id1, id2...;.

    Data Types in C

    • C supports four classes of data types:
      • Basic Data Types: Fundamental types for variables (e.g., int, char, float, double).
      • Derived Data Types: Types that store sets of values (e.g., arrays, structures).
      • User Defined Data Types: Custom types using typedef.
      • Pointer Data Types: Types for storing memory addresses.

    Constants in C

    • Constants do not change during program execution, classified into numeric (e.g., integer, floating-point) and character constants.
    • Escape sequences (e.g., \n, \t) represent special characters in strings.

    Enumeration Constants

    • Enumerations provide named constants with sequential integer values, improving code readability.

    This condensed guide summarises the primary aspects of C programming, its history, structure, and key features.### Variables in C

    • A variable is a symbolic name for a memory location used to store data.
    • Variables can be reused, and their values can be changed, making them versatile.
    • Syntax for declaring a variable: type variable_list;
    • Examples of variable declarations:
      • int a;
      • float b;
      • char c;
    • Initialization of variables can be done at declaration:
      • int a=10, b=20;
      • float f=20.8;
      • char c='A';

    Rules for Defining Variables

    • Variable names can include alphabets, digits, and underscores.
    • Variable names must start with an alphabet or underscore and cannot begin with a digit.
    • Whitespace is prohibited within variable names.
    • Reserved keywords (e.g., int, float) cannot be used as variable names.

    Valid vs Invalid Variable Names

    • Valid names:
      • int a;
      • int _ab;
      • int a30;
    • Invalid names:
      • int 2;
      • int a b;
      • int long;

    Types of Variables in C

    • Local Variable: Declared within a function or block, must be initialized before use.
      • Example: void function1() { int x=10; }
    • Global Variable: Declared outside any function, accessible from any function.
      • Example: int value=20;
    • Static Variable: Retains its value across multiple function calls and is declared using the static keyword.
      • Example behavior: x remains constant, while y increments with each function call.
    • Automatic Variable: Default for all variables in C, declared inside a block.
      • Example: auto int y=20;
    • External Variable: Used for sharing a variable across multiple C source files, declared with the extern keyword.
      • Example: extern int x=10;

    Storage Classes in C

    • Storage classes determine a variable's lifetime, visibility, memory allocation, and initial value.
    • Four main types: Automatic, External, Static, Register.

    Storage Class Details

    • Automatic:

      • Memory allocated at runtime.
      • Limited visibility and scope confined to the defining block.
      • Default initialization to garbage values.
      • Memory is freed upon exiting the block.
      • Keyword: auto.
    • External:

      • Resides in RAM and initialized to zero.
      • Global scope and lasts until the end of the main program.
      • Can be declared anywhere in the program.
    • Static:

      • Resides in RAM and initialized to zero.
      • Local scope and retains value across function calls.
      • Lifetime lasts until the end of the main program.
    • Register:

      • Stored in CPU registers rather than RAM.
      • Initialization to garbage values.
      • Local scope and lifetime confined to the defining block.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Learn about the history and development of the C programming language, starting from its origins at Bell Laboratories in 1972 to its standardization by the American National Standards Institute (ANSI) in 1983. Explore how C became closely associated with UNIX and its efficient approach to computer programming.

    More Like This

    C Programming
    5 questions

    C Programming

    SteadiestOlive avatar
    SteadiestOlive
    History of C Programming Language
    151 questions
    History of C Programming Language
    10 questions
    Use Quizgecko on...
    Browser
    Browser