quiz image

History of C Programming Language

SprightlyVision avatar
SprightlyVision
·
·
Download

Start Quiz

Study Flashcards

57 Questions

What was the original goal of the American National Standards Institute (ANSI) committee established in 1983 related to the C programming language?

To produce an unambiguous and machine independent definition of the language C

Which programming language was UNIX primarily written in?

C

What makes UNIX one of the first portable operating systems?

The majority of the code does not know or care about the computer it is running on

Who originally designed the C programming language for use with UNIX on DEC PDP-11 computers?

Dennis Ritchie

Which book was the first publication about the C programming language, authored by Brian Kernighan and Dennis Ritchie?

The C Programming Language

What was one of the earlier forms of the C language before it evolved from B?

BCPL

What is the purpose of local declarations in a C program?

To declare variables inside a given function or block

Which of the following statements is considered part of a C program?

switch, case

In C programming, what is the purpose of user-defined functions?

To specify operations as needed by the user

What is the role of the return function in C programs?

To end the execution of a function

Why must every file containing a C program be saved with a '.c' extension?

To allow linking with library functions

What is the purpose of the linker in C programming?

To link object files with library functions

Which component loads the executable file into RAM during program execution?

Loader

What does the Instruction Register do during program execution?

Holds the current instructions for CPU execution

'Program Counter' in C programming is responsible for:

Holding the address of the next instruction to be executed

What does the Accumulator store during program execution in C programming?

Information related to calculations

What is the name of the recognized standard for C language established by ANSI?

ANSI C

Which organization established a standard for C similar to ANSI C?

ISO

What is the primary advantage of using C for writing programs?

Efficiency and portability

Which section of a C program includes program's name, date, and description?

Documentation section

What purpose does the preprocessor section serve in a C program?

Link header files to system libraries

Which keyword is used to declare constants in the define section of a C program?

#define

What is the purpose of the main function in a C program?

To start program execution

'void main()' versus 'int main()' in C programming primarily differs in:

Returned value type

Why is C considered well-suited for writing both system and application software?

Availability of several data types and operators.

What is the output of the following code snippet?

#include int main() {
    int a, b, sum;
    printf("Enter two no: ");
    scanf("%d %d", &a, &b);
    sum = a + b;
    printf("Sum : %d", sum);
    return(0);
}

Given Input: 3 7

Enter two no: Sum : 10

What does the C function 'ceil(number)' do?

Rounds up the given number to the nearest integer

Which of the following is NOT a C keyword?

print

What does the 'pow(base, exponent)' function do in C?

Returns the power of the given number

In C programming, what do identifiers refer to?

Names of variables and program elements like functions

What is an essential requirement for declaring identifiers in C programming?

Not being a reserved keyword

What is the purpose of assigning values to variables in a C program?

To store and manipulate data during program execution

'sizeof' is an example of which of the following in C programming?

'C' operator to determine memory consumption

'int_amt=(prt)/100;' in C programming is an example of what?

Assignment operation with arithmetic expression

Which function in C programming rounds down a given number?

floor(number)

Which type of variable retains its value between multiple function calls?

Static variable

What is the default visibility scope of automatic variables in C?

Local

In C, where must global variables be declared?

Outside any function or block

What is the purpose of the static keyword when declaring a variable in C?

To retain the variable's value between function calls

Which storage class is associated with automatic variables in C?

Auto

What is the default lifetime of static variables in C?

Till the end of the main program

Which symbol is not allowed to start a variable name in C?

(hash)

'int long' is an invalid variable name in C because:

'int long' is a reserved keyword in C.

'extern int x=10;' declares an external variable with an initial value. Why might this declaration cause issues?

'extern' variables should not be explicitly initialized.

Which data type is used to store the address of a variable in C?

Pointer data type

What is the range of an unsigned char data type in C?

0 to 255

Which of the following is an example of a derived data type in C?

Array

What is the purpose of using typedef in C?

To create new variable names

What do escape sequences represent in C?

Control characters like newline, tab

Which type of constant allows for increasing the storage range in C?

Unsigned constant

'I am a little boy' would be classified as:

'I' string constant

'typedef int Integer;' statement creates a synonym for which data type?

'int'

Which storage class in C allows variables to hold their value between multiple function calls?

Static

In C, which storage class allows variables to be stored in the CPU registers?

Register

What happens if you try to dereference a register variable in C?

It is not allowed and will result in a compilation error

What does the extern storage class declaration indicate in C?

Variable is declared elsewhere with external linkage

What does the compiler do if an extern variable in C is not initialized within the program?

Searches for it to be initialized somewhere in the program

Study Notes

History of C

  • The C language was first proposed in 1972 by Dennis M. Ritchie at Bell Laboratories, USA.
  • In 1983, the American National Standards Institute (ANSI) established a committee to standardize the definition of C, resulting in ANSI C.
  • ANSI C is the recognized standard for the language, grammar, and core set of libraries.

Characteristics of C

  • C is a robust language with a rich set of built-in functions, data types, and operators.
  • Programs written in C are efficient due to the availability of several data types and operators.
  • C is a highly portable language, allowing code written on one machine to be easily moved to another.
  • C supports low-level features like bit-level programming and direct access to memory using pointers.

Basic Structure of a C Program

  • A C program consists of several sections, including:
    • Documentation section (includes comments and program description)
    • Preprocessor section (includes header files and library links)
    • Definition section (includes constants and macros)
    • Global declaration section (includes global variables and functions)
    • Main function (the entry point of the program)
    • User-defined functions (custom functions written by the programmer)

Program Execution

  • When a C program is compiled and executed, the compiler generates several files, including:
    • Source file (with a .c extension)
    • Object file (with a .obj extension)
    • Executable file (with a .exe extension)
  • The program is executed in the following steps:
    1. The loader loads the executable file into RAM and informs the CPU of the starting point.
    2. The CPU executes the program, using the Instruction Register and Program Counter.

C Math Functions

  • C provides several math functions, including:
    • ceil() (rounds up a number)
    • floor() (rounds down a number)
    • sqrt() (returns the square root of a number)
    • pow() (returns the power of a number)
    • abs() (returns the absolute value of a number)

C Tokens

  • Tokens are the individual units of a C program, including:
    • Keywords (reserved words with specific meanings)
    • Identifiers (names of variables, functions, and arrays)
    • Constants (numeric, character, or string values)
    • Operators (symbols used for arithmetic, comparison, and logical operations)
    • Punctuators (symbols used for grouping and separating tokens)

Keywords

  • Keywords are reserved words in C, including:
    • auto
    • double
    • int
    • struct
    • break
    • else
    • long
    • switch
    • ...

Identifiers

  • Identifiers are names of variables, functions, and arrays, and must follow certain rules:
    • Can be named from a combination of A-Z, a-z, 0-9, and _
    • First character must be an alphabet or underscore
    • Must not be a keyword
    • Can be up to 31 characters long

Data Types

  • C provides several data types, including:
    • int
    • float
    • char
    • double
    • long
    • short
    • unsigned
    • ...

Variables

  • Variables are named storage locations that can hold different values, and can be:
    • Local (declared inside a function or block)
    • Global (declared outside a function or block)
    • Static (retains its value between multiple function calls)
    • Automatic (allocated memory automatically at runtime)
    • External (shared across multiple C source files)

Storage Classes

  • Storage classes in C determine the lifetime, visibility, memory location, and initial value of a variable, including:
    • Automatic
    • External
    • Static
    • Register### C Data Types
  • C supports four classes of data types: basic, derived, user-defined, and pointer data types.

Basic Data Types

  • Basic data types support arithmetic operations such as addition and subtraction.
  • Examples: int a, b;, char c;
  • Storage size and range of basic data types:
    • Unsigned char: 8 bits, 0 to 255
    • Char: 8 bits, -128 to 127
    • Short int: 16 bits, -32768 to 32767
    • Unsigned int: 32 bits, 0 to 4294967295
    • Int: 32 bits, -2147483648 to 2147483648
    • Unsigned long: 32 bits, 0 to 4294967295
    • Enum: 16 bits, -2147483648 to 2147483648
    • Long: 32 bits, -2147483648 to 2147483648
    • Float: 32 bits, 3.4e-38 to 3.4e38
    • Double: 64 bits, 1.7e-308 to 1.7e308
    • Long double: 80 bits, 3.4e-4932 to 1.1e4932

Derived Data Types

  • Derived data types store a set of data values.
  • Examples: arrays and structures.

User-Defined Data Types

  • C provides a facility called typedef for creating new data type names defined by the user.
  • Example: typedef int Integer; makes Integer a synonym of int.

Pointer Data Types

  • Pointer data types store the address of a variable.

Constants

  • A constant is a quantity that does not vary during the execution of a program.
  • Two types of constants: numeric and character constants.

Numeric Constants

  • Examples: 786, -127, 1234567899L (long constant)
  • Unsigned constants: 123456789u (unsigned constant), 1234567891ul (unsigned long constant)
  • Advantage of declaring an unsigned constant: increases the range of storage.
  • Floating-point constants: 123.4, 1e-2, 1.4E-4

Character Constants

  • A character constant is written as one character within single quotes, e.g. 'a'.
  • Escape sequences: \a (alert), \b (backspace), \f (form feed), \n (new line), \r (carriage return), \t (horizontal tab), \v (vertical tab)

String Constants

  • A string constant is a sequence of zero or more characters surrounded by a double quote, e.g. " I am a little boy".
  • Quotes are not part of the string.

Enumeration Constants

  • An enumeration constant is a list of constant integer values, e.g. enum color { RED, Green, BLUE }.
  • The first name in the enum has the value 0, and the next 1, and so on unless explicit values are specified.

Variables

  • auto variables: default initial value is garbage.
  • static variables:
    • Hold their value between multiple function calls.
    • Visible only to the function or block in which they are defined.
    • Can be declared many times but can be assigned at only one time.
    • Default initial value of static integral variables is 0 otherwise null.
  • register variables:
    • Allocated memory into the CPU registers.
    • Can not be dereferenced (i.e., can not use & operator).
    • Access time is faster than automatic variables.
    • Initial default value of register local variables is 0.
    • Can store pointers into the register.
  • extern variables:
    • Used to tell the compiler that the variable is declared with an external linkage elsewhere in the program.
    • Not allocated any memory.
    • Default initial value of external integral type is 0 otherwise null.
    • Can only initialize the extern variable globally.
    • Can be declared many times but can be initialized at only once.

Explore the evolution and milestones of the C programming language, which originated at Bell Laboratories in 1972. Learn about the standardization efforts by ANSI and its association with UNIX.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser