Podcast
Questions and Answers
Who created the C programming language?
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.
The C programming language was developed before the B programming language.
False (B)
What are two research interests of Dr. Frank Guan?
What are two research interests of Dr. Frank Guan?
Virtual Reality and Artificial Intelligence
C was created by _______ at Bell Lab.
C was created by _______ at Bell Lab.
Match the programming languages with their main features:
Match the programming languages with their main features:
What is one of the suggested formats for questions during the lecture?
What is one of the suggested formats for questions during the lecture?
The lecture is conducted in person.
The lecture is conducted in person.
Which book is recommended for learning C programming?
Which book is recommended for learning C programming?
Which year was the C99 standard introduced?
Which year was the C99 standard introduced?
C programming language supports garbage collection.
C programming language supports garbage collection.
What are the names of the lead developers of UNIX?
What are the names of the lead developers of UNIX?
C is a ______-level language, which typically results in faster code execution.
C is a ______-level language, which typically results in faster code execution.
Which of the following languages were influenced by C?
Which of the following languages were influenced by C?
Match each programming feature with the appropriate language:
Match each programming feature with the appropriate language:
In Python, variable declarations are mandatory.
In Python, variable declarations are mandatory.
What does a compiler do in the context of C programming?
What does a compiler do in the context of C programming?
What symbol is used to terminate statements in C?
What symbol is used to terminate statements in C?
The main() function is an optional part of a C program.
The main() function is an optional part of a C program.
What is the purpose of using braces {} in C?
What is the purpose of using braces {} in C?
In C programming, all code must be placed within __________.
In C programming, all code must be placed within __________.
Match the following programming constructs with their language:
Match the following programming constructs with their language:
Flashcards
C Programming Language
C Programming Language
A general-purpose, imperative computer programming language, notable for its efficiency and use in system programming.
Origins of C
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
Compiler
A program that translates source code (human-readable text) into machine code (computer instructions).
Data Types
Data Types
Signup and view all the flashcards
Basic C Syntax
Basic C Syntax
Signup and view all the flashcards
Variables
Variables
Signup and view all the flashcards
Formatted I/O
Formatted I/O
Signup and view all the flashcards
Control Structures (C)
Control Structures (C)
Signup and view all the flashcards
C code blocks
C code blocks
Signup and view all the flashcards
C function
C function
Signup and view all the flashcards
C whitespace
C whitespace
Signup and view all the flashcards
Function main()
Function main()
Signup and view all the flashcards
C statement terminator
C statement terminator
Signup and view all the flashcards
C Variable Declaration
C Variable Declaration
Signup and view all the flashcards
C vs. Python (Compilation)
C vs. Python (Compilation)
Signup and view all the flashcards
C Language Evolution
C Language Evolution
Signup and view all the flashcards
Python Whitespace
Python Whitespace
Signup and view all the flashcards
C Language Features
C Language Features
Signup and view all the flashcards
Machine Code
Machine Code
Signup and view all the flashcards
Interpreter
Interpreter
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
Recommended Reading
- 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
C vs. Related Languages
- 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 libraryint main() { ... }
defines the main program functionprintf("Hello world!\n");
displays output on the screenreturn 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.
- Uses format specifiers (e.g.,
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-makingswitch
for multiple-case decisionsfor
andwhile
loops for iterationdo-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()
andcalloc()
. 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.
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.