C Programming Language Quiz
21 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

Who created the C programming language?

  • J. Presper Eckert
  • Ken Thompson
  • Martin Richard
  • Dennis Ritchie (correct)

The C programming language was developed before the B programming language.

False (B)

What are two research interests of Dr. Frank Guan?

Virtual Reality and Artificial Intelligence

C was created by _______ at Bell Lab.

<p>Dennis Ritchie</p> Signup and view all the answers

Match the programming languages with their main features:

<p>C = Low-level programming Python = High-level programming Java = Object-oriented programming Assembly = Machine-level instructions</p> Signup and view all the answers

What is one of the suggested formats for questions during the lecture?

<p>Voice up (D)</p> Signup and view all the answers

The lecture is conducted in person.

<p>False (B)</p> Signup and view all the answers

Which book is recommended for learning C programming?

<p>C: How to Program by Paul Deitel and Harvey Deitel</p> Signup and view all the answers

Which year was the C99 standard introduced?

<p>1999 (D)</p> Signup and view all the answers

C programming language supports garbage collection.

<p>False (B)</p> Signup and view all the answers

What are the names of the lead developers of UNIX?

<p>Dennis Ritchie and Ken Thompson</p> Signup and view all the answers

C is a ______-level language, which typically results in faster code execution.

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

Which of the following languages were influenced by C?

<p>Java (C), Python (D)</p> Signup and view all the answers

Match each programming feature with the appropriate language:

<p>C = Requires variable declarations Python = Uses whitespace to identify statements C++ = Supports object-oriented programming Java = Garbage collection enabled</p> Signup and view all the answers

In Python, variable declarations are mandatory.

<p>False (B)</p> Signup and view all the answers

What does a compiler do in the context of C programming?

<p>Converts source code into machine code.</p> Signup and view all the answers

What symbol is used to terminate statements in C?

<p>; (A)</p> Signup and view all the answers

The main() function is an optional part of a C program.

<p>False (B)</p> Signup and view all the answers

What is the purpose of using braces {} in C?

<p>To delimit blocks of code.</p> Signup and view all the answers

In C programming, all code must be placed within __________.

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

Match the following programming constructs with their language:

<p>gcd function = C def keyword = Python printf function = C return statement = Both</p> Signup and view all the answers

Flashcards

C Programming Language

A general-purpose, imperative computer programming language, notable for its efficiency and use in system programming.

Origins of C

C evolved from the language BCPL, which was itself inspired by B. Core features of the language were further conceived in Unix.

Compiler

A program that translates source code (human-readable text) into machine code (computer instructions).

Data Types

Defined categories of data that a program can use, such as integers, floats, and strings.

Signup and view all the flashcards

Basic C Syntax

A set of rules for writing and structuring C programs.

Signup and view all the flashcards

Variables

Named storage locations that holds data in a program.

Signup and view all the flashcards

Formatted I/O

Input and output operations in a computer program.

Signup and view all the flashcards

Control Structures (C)

Statements that control the flow of execution in a program, such as loops (for, while) and conditional statements (if, else).

Signup and view all the flashcards

C code blocks

Code blocks in C are delimited using curly braces {}.

Signup and view all the flashcards

C function

A self-contained block of code that performs a specific task; C programs must have a main() function.

Signup and view all the flashcards

C whitespace

Whitespace in C is used primarily to separate words.

Signup and view all the flashcards

Function main()

The 'starting point' of any C program that calls other functions.

Signup and view all the flashcards

C statement terminator

C statements need a semicolon (;) at the end.

Signup and view all the flashcards

C Variable Declaration

A necessary step where you tell the compiler the type of a variable before using it, and this type cannot be changed later.

Signup and view all the flashcards

C vs. Python (Compilation)

C uses compilers to translate source code into machine code, while Python employs interpreters.

Signup and view all the flashcards

C Language Evolution

C has gone through several standardization stages (e.g., C89, C99) to improve consistency and address variations in implementation.

Signup and view all the flashcards

Python Whitespace

Whitespace (spaces and tabs) is crucial in Python to determine the structure and flow of the program.

Signup and view all the flashcards

C Language Features

Features are: lacks range-checking, garbage collection, and direct object-oriented programming support.

Signup and view all the flashcards

Machine Code

The low-level instructions that the CPU directly executes once compiled

Signup and view all the flashcards

Interpreter

A program/system that translates and executes one line of code at a time, without requiring full compilation to machine code first.

Signup and view all the flashcards

Study Notes

Introduction to C Programming

  • Welcome to the course
  • Instructor: A/Prof Frank Guan, PhD
  • Course name: INF1002 – Programming Fundamentals
  • Week 8: Introduction to C
  • Course themes: Thinking, Able to Learn, Catalysts, and Grounded, as a community, transformative learning
  • Research Interests: Virtual Reality (VR), Augmented Reality (AR), Artificial Intelligence (AI), Entrepreneurship & innovation
  • Contact Email: [email protected]

Course Housekeeping

  • Lectures are online (Zoom)
  • Recordings are available
  • Focus on the lecture and limit distractions
  • Ask questions: voice up or type in the window
  • Respectful and honest conduct within the community

Agenda for Week 8

  • History of C
  • From Python to C
  • Simple C program
  • Basic data types
  • C formatted I/O
  • Control structures
  • Paul Deitel and Harvey Deitel, C: How to Program, 9th Edition (Pearson, 2021)

History of C

  • J. Presper Eckert and John Mauchly (1943–1946): Electronic Numerical Integrator and Computer
  • Martin Richard (1966–1967): Basic Combined Programming Language
  • Ken Thompson (1969, Bell Lab): Developed B, based on BCPL
  • Dennis Ritchie (1972–1973, Bell Lab): Created C, rewriting UNIX in C (1973)
  • 1970s: Traditional C
  • 1989: C89/ANSI C/Standard C
  • 1990: ANSI/ISO C
  • 1999: C99: attempt to standardize variations
  • More recent derivatives: C++, Objective C, C#
  • Influenced by: Java, Perl, Python (quite different)
  • C lacks: Exceptions, Range-checking, Garbage collection, Object-oriented programming
  • Low-level languages, usually faster code

Compilers vs. Interpreters

  • Python uses an interpreter to execute a program
  • In C, the compiler converts a program into machine code
  • Machine code can be executed directly by the CPU

Variable Declarations

  • C requires variable declarations, informing the compiler about the variable before it's used, specifying type.
  • Once declared, a variable's type cannot be changed.
  • In Python, no declarations are needed.

Whitespace

  • Python uses whitespace characters for identifying statements and code blocks
  • C uses whitespace only to separate words.

Functions

  • All C code is within functions
  • The main() function is the starting point for a C program

Good Coding Practices in C

  • Indent blocks of code as in Python.
  • Format braces and whitespace consistently
  • Use comments to explain code for other programmers.
  • Use meaningful variable names.
  • Pay attention to compiler warnings (indicate syntax correct but potential run-time errors).
  • Avoid system-specific features (the code should run on diverse systems without modification).

Simple C Program

  • /* ... */ indicates comments (ignored by the compiler)
  • #include <stdio.h> includes the standard input/output library
  • int main() { ... } defines the main program function
  • printf("Hello world!\n"); displays output on the screen
  • return 0; signifies successful execution.

C Preprocessor

  • Executes before compilation
  • Defines symbolic constants
  • Includes other files

#define directive

  • Creates symbolic constants in C
  • Replaces occurrences during compilation.

#include directive

  • Includes header files into the program for necessary functions (such as stdio.h for standard input/output)
  • Normal usage includes angle brackets <> (standard libraries) or double quotes "" (user-defined files) for specifying location
  • Two forms of #include specify standard or user-defined file location.

Header files

  • Contain function prototypes (declarations without body):
  • Definitions of constants.
  • Definitions of various data types.

Variable Declarations in C

  • Must specify type before use (int, float, char).
  • Variables cannot change type once declared.
  • Variables are named integer1, integer2, sum

scanf() Function in C

  • Reads formatted input from the standard input (usually the keyboard)

Formatted Input/Output

  • printf() formats and displays output to the console
    • Uses format specifiers (e.g., %d, %f, %s) to define the output format.
  • scanf() reads input from the console
    • Uses format specifiers for input.
  • puts() prints a string and prepends a newline at the end.
  • getchar() reads and returns a character from the console as an integer

Escape Sequences

  • Used to represent special characters in strings
  • Examples include \n (newline), \t (tab), and \" (double quote)

C Control Structures

  • if/else for decision-making
  • switch for multiple-case decisions
  • for and while loops for iteration
  • do-while loop

Arrays

  • An array is a collection of elements of the same type, stored contiguously in memory.
  • Character arrays are used to represent strings.
  • Arrays can be declared/initialised, and array elements can be identified using indices, starting with zero.

Structure

  • A structure in C is a collection of variables of different types, grouped together under one name.
  • Structures can be passed to functions in C

Dynamic Memory Allocation

  • Allocates memory at runtime
  • Allocates memory for variables that are not known in advance, using malloc() and calloc() .
  • malloc(): Allocates a block of memory in heap.
  • calloc(): Allocates a block of memory and sets all bytes to zero.

Void Pointers

  • Can point to any data type
  • Should be cast before dereferencing

Pointers

  • Variables that stores memory addresses
  • Declaration via int *ptr

Strings

  • Array of characters ending in \0

C File Handling

  • fopen(): Opens a file.

fprintf()

  • Writes formatted data to a file.

fscanf()

  • Reads formatted data from a file.

fclose()

  • Closes a file.

File Types

  • Binary or text

Random Access Files

  • Can access any file position.
  • Records are of the same length.

Studying That Suits You

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

Quiz Team

Related Documents

Description

Test your knowledge about the C programming language with this comprehensive quiz. Explore its history, features, and key concepts, including important developers and standards. Whether you are a beginner or have some experience, this quiz will challenge your understanding of C.

Use Quizgecko on...
Browser
Browser