Podcast
Questions and Answers
Who created the programming language C?
Who created the programming language C?
What makes C a popular choice for learning other programming languages?
What makes C a popular choice for learning other programming languages?
Which of the following best states a primary difference between C and C++?
Which of the following best states a primary difference between C and C++?
Which of the following is considered a feature of C?
Which of the following is considered a feature of C?
Signup and view all the answers
What does ANSI stand for in relation to the C programming language?
What does ANSI stand for in relation to the C programming language?
Signup and view all the answers
Which IDE is recommended for beginners learning C programming?
Which IDE is recommended for beginners learning C programming?
Signup and view all the answers
Why might C be considered a low-level language?
Why might C be considered a low-level language?
Signup and view all the answers
Which file is recommended to install for setting up the Code::Blocks IDE with a compiler?
Which file is recommended to install for setting up the Code::Blocks IDE with a compiler?
Signup and view all the answers
What is the purpose of the initializer in a for loop?
What is the purpose of the initializer in a for loop?
Signup and view all the answers
What happens if the termination condition in a for loop evaluates to false?
What happens if the termination condition in a for loop evaluates to false?
Signup and view all the answers
What is a common way to express an infinite loop in a for loop?
What is a common way to express an infinite loop in a for loop?
Signup and view all the answers
How can arithmetic expressions be utilized in a for loop?
How can arithmetic expressions be utilized in a for loop?
Signup and view all the answers
Which of the following for loops is equivalent to a while loop?
Which of the following for loops is equivalent to a while loop?
Signup and view all the answers
Which part of a simple program is responsible for storing values?
Which part of a simple program is responsible for storing values?
Signup and view all the answers
Why must variables be declared before being assigned values?
Why must variables be declared before being assigned values?
Signup and view all the answers
What is the correct assignment statement for a float variable named 'x'?
What is the correct assignment statement for a float variable named 'x'?
Signup and view all the answers
Which of the following variable names follows proper naming conventions in C?
Which of the following variable names follows proper naming conventions in C?
Signup and view all the answers
How many characters should a variable name ideally have to ensure portability?
How many characters should a variable name ideally have to ensure portability?
Signup and view all the answers
In C, what is the purpose of the main body of a program?
In C, what is the purpose of the main body of a program?
Signup and view all the answers
Which of the following statements correctly describes a constant in programming?
Which of the following statements correctly describes a constant in programming?
Signup and view all the answers
What characters are allowed in a C variable name?
What characters are allowed in a C variable name?
Signup and view all the answers
Which operator is used for variable assignment in C?
Which operator is used for variable assignment in C?
Signup and view all the answers
What type of variable can hold a single character in C?
What type of variable can hold a single character in C?
Signup and view all the answers
What does the atoi function do with a String argument?
What does the atoi function do with a String argument?
Signup and view all the answers
What does the printf statement output in the example with atoi when 'test2 333' is executed?
What does the printf statement output in the example with atoi when 'test2 333' is executed?
Signup and view all the answers
What is the primary purpose of the getchar function?
What is the primary purpose of the getchar function?
Signup and view all the answers
In a while loop, what happens if the expression evaluates to false?
In a while loop, what happens if the expression evaluates to false?
Signup and view all the answers
What will the following loop do: 'while (1) { putchar(c); c = getchar(); }'?
What will the following loop do: 'while (1) { putchar(c); c = getchar(); }'?
Signup and view all the answers
What error message is displayed if argc is less than 2 in the if statement example?
What error message is displayed if argc is less than 2 in the if statement example?
Signup and view all the answers
Which control statement is considered less favorable and typically avoided?
Which control statement is considered less favorable and typically avoided?
Signup and view all the answers
What is a primary difference between for loops and while loops?
What is a primary difference between for loops and while loops?
Signup and view all the answers
What is the purpose of the break statement within loops?
What is the purpose of the break statement within loops?
Signup and view all the answers
In a do-while loop, what distinguishes it from a standard while loop?
In a do-while loop, what distinguishes it from a standard while loop?
Signup and view all the answers
What is the correct way to calculate the ratio of female to male students?
What is the correct way to calculate the ratio of female to male students?
Signup and view all the answers
What is the first step in the structure of a C program?
What is the first step in the structure of a C program?
Signup and view all the answers
Which of the following is NOT a valid variable declaration in C?
Which of the following is NOT a valid variable declaration in C?
Signup and view all the answers
What must always follow variable declarations in a C program?
What must always follow variable declarations in a C program?
Signup and view all the answers
Which statement is true about C program statements?
Which statement is true about C program statements?
Signup and view all the answers
What is the purpose of the printf function in C?
What is the purpose of the printf function in C?
Signup and view all the answers
Which of the following statements about formatting and whitespace in C is correct?
Which of the following statements about formatting and whitespace in C is correct?
Signup and view all the answers
Which of the following represents an assignment expression in C?
Which of the following represents an assignment expression in C?
Signup and view all the answers
What does the statement 'int g = 1, h, k = 3;' signify?
What does the statement 'int g = 1, h, k = 3;' signify?
Signup and view all the answers
Which of the following is NOT a feature of executable statements in C?
Which of the following is NOT a feature of executable statements in C?
Signup and view all the answers
Study Notes
IT101 IT Fundamentals
- Course instructors: Dr. Islam Taj-Eddin, Dr. Ali Hussein Ahmed, Dr. Tarik Mohamed Abdel-Kader Ibrahim, Dr. Ebram Kamal William Aziz
- Department: IT Department, Faculty of Computers and Information
- University: Assiut University
- Academic year: 2024-2025
Course Enrollment
- Learning management system (LMS): Thinqi LMS
- Course code: IT101-1
- Group: 1 - 2024/2025
- Course name: IT Fundamentals
- Enroll using the provided QR code at the given URL: https://aun.edu.eg/thinqi
Lecture 7&8
- Topic: Programming
- Number of the lecture: 7 & 8
What is C?
- Programming language created by Dennis Ritchie at Bell Laboratories in 1972
- A versatile, popular language, despite its age
- Closely associated with the UNIX operating system, as it was designed for its development
Why Learn C?
- One of the most popular programming languages globally
- Learning C lays a strong foundation for other languages (Java, Python, C++, C#) due to similar syntax
- Compiled language, making it significantly faster compared to interpreted languages (like Java and Python)
Difference between C and C++
- C++ is an extension of C
- Both languages share a similar syntax
- C++ supports classes and objects; C does not
C Programming Language
- Structured, relatively low-level, and portable programming language
- It influences many other programming languages
- Forces understanding of fundamental programming concepts.
- Characterized by its conciseness
C, Continued
- Not an object-oriented language (C++ is)
- Can be useful as a non-object-oriented language
- Learning curve is manageable.
- ANSI standard defines C for portability
C Install IDE
- Integrated Development Environment (IDE) is used to edit and compile code
- Popular IDEs include Code::Blocks, Eclipse, and Visual Studio. These are all freely available
- Web-based IDEs are also available but may have limitations in functionality
- Code::Blocks is used in tutorials as a strong and effective choice
- Download the
mingw-setup.exe
file from http://www.codeblocks.org/ - Online compilers are available at https://www.programiz.com/c-programming/online-compiler/
C Data Types
- Topic: C data types
What do program instructions look like?
- Simple programs generally contain at least:
- Variable declaration
- Variable initialization
- Main body
Variables in Programming
- Representing storage units in a program
- Used for storing and retrieving data throughout program execution
- Variable type dictates the data it can hold
- Variables are declared before assignment.
- Variables can change values; constants remain constant
Naming Variables
- Variables are assigned names when declared
- Good programming practices: choose names that reflect the variables' roles in the program (e.g., customer_name, ss_number) Avoid vague or confusing abbreviations
- Avoid overly long names unless readability improves.
- Naming restrictions: variable names must begin with a letter and can contain letters, digits, and underscores. C is case-sensitive; use 31 or fewer characters for portability
Variable Declaration
- All variables must be declared in a C program before the first executable statement
- Examples of declarations for integer and float types can be found in the slides
C Variable Names
- Variables in C consist of letters, digits and underscores, and cannot start with a digit
- Variable names are case-sensitive
- ANSI standards limit variable names to 31 characters or less
Variable assignment
- After declaring a variable, it should be given a value through assignment using the equals operator (
=
)
Basic C variable types
- There are four basic types in C:
- char: A single byte holding a character from the local character set.
- int: Represents an integer of a size that varies based on the machine architecture.
- float: Single-precision floating-point number
- double: Double-precision floating-point number
char variable type
- Represents a single byte (8 bits) of storage
- Can be signed or unsigned
- Internals are numerical values associated with characters (ASCII) via a character set
int variable type
- Represents a signed integer, typically using 4 bytes (32 bits)
Char vs. Int
- Both can perfectly represent the same number (e.g., 4)
- Ints store more memory but can also hold numbers larger than 255 -Chars typically represent a single byte and have a limited range
Char, Continued
- Avoid using char for larger numbers to prevent data loss situations
Float and Double Variable Types
- These represent real numbers, typically using 32 and 64 bits respectively
Additional variable types
- Other variable types can be created using modifiers (e.g., short, long, signed, unsigned)
- Exact sizes depend on the machine, and are not essential for basic programming for this course.
Declaring Variables
- All variables should be declared before executable instructions
- A declaration includes the variable's type followed by its name (e.g.,
int age;
,float annual_salary;
)
Assigning Values to Variables
- Variable assignments can be done directly in the declaration or after declarations
- Use the
=
assignment operator (e.g.,output = input + 1;
)
Assignment, Continued
- Be mindful of variable types when assigning values.
- Ensure that assignment won't cause an overflow
Type conversions in expressions
- Implicit type conversion occurs when mixing data types in an expression
- The lower type is promoted to the higher type.
- C allows mixing of data types in an expression, converting smaller types into larger type before the expression evaluates, for instance converting short to int before computing an expression with int values.
Order of Data Types
- Data types are ordered in terms of their size or range.
- Larger types generally precede smaller types in the ordering
Printf() examples
- printf("string"); Prints a string to the console.
- printf("%d", variable); Prints the integer value of the variable to the console.
Reading keyboard input
- Scanf function reads input from user input from the keyboard.
- It is like printf but it is for reading user input
Scanf function
- Syntax:
scanf(format, &variable)
- Format specifiers are similar to printf.
Another technique for passing data from the keyboard
- Passing data to a C program using argc and argv
Passing data, cont
- Tokens are stored as separate elements of the
argv
array -
argc
stores the count of tokens, useful for looping
Argv/argv example
- Example illustrating
argc
andargv
usage
Argv/argv cont
- Processing command-line arguments (tokens) is necessary to handle command-line arguments for advanced scenarios
Converting String to integer
-
atoi
function converts a string to an integer
Reading single characters
-
getchar/putchar
reads/writes characters to/from the console. -
getchar
waits until input is available from stdin—keyboard—or returns immediately if it is EOF.
While loops
- Repeating statements based on a condition.
- Syntax:
while (condition) { ... }
condition tested at the beginning of the loop - Looping continues as long as the expression is true. Example:
While example
- Example demonstrating a while loop, inputting from user
- Includes declarations.
If example
- Includes control flow using
if
statement - Includes checks for arguments before entering the loop for validity. Also handles the case where a program only receives its name as an argument.
Getchar/putchar example
- This includes a do-while loop, reading characters one by one
More control statements
- Additional control flow concepts, beyond
if
,while
, and loops
For loops
- Syntax for
for
loops, equivalent towhile
loops - Initialization, condition, and increment parts are separated by semicolons
- Looping structure
For loops, cont
- Specific components of the
for
loop syntax, including initialization and increment clauses, and the termination condition - Notes about
for
loop increments
Switch statements
- A multi-way branching structure switch( expression ) { case value1: // statements break; case value2: // statements break; default: // statements }
- Using
break
is crucial to prevent fall-through from one case to another
Switch, cont
- Case values must be constants
-
break
statements inswitch
are important - Cleaner alternative for if-else
Switch flow-chart
- Flow chart representation of
switch
statements
do/while Repetition Structure
- Condition tested at the end of the loop, ensuring the loop runs at least once.
- Structure:
do{ ... } while(condition);
Do-while example
- Sample usage of
do-while
loop
Summary of Control Statements
- Additional control flow statements in C (for, switch, do-while)
- How they increase the versatility and efficiency of programming code
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz focuses on Lectures 7 and 8 of the IT101 IT Fundamentals course, covering the C programming language. Delve into the history, significance, and reasons to learn C, a vital foundation for many modern programming languages. Perfect for students aiming to solidify their programming skills.