IT101 IT Fundamentals - Lectures 7 & 8
43 Questions
1 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 programming language C?

  • Guido van Rossum
  • Dennis Ritchie (correct)
  • James Gosling
  • Bjarne Stroustrup

What makes C a popular choice for learning other programming languages?

  • It has additional features like automatic memory management.
  • It requires advanced programming knowledge to understand.
  • It is an object-oriented language.
  • Its syntax is similar to many other languages. (correct)

Which of the following best states a primary difference between C and C++?

  • C supports classes and objects.
  • C++ is a structured, low-level language.
  • C is specifically for Windows programming.
  • C++ supports classes and objects, while C does not. (correct)

Which of the following is considered a feature of C?

<p>It is a general-purpose programming language. (B)</p> Signup and view all the answers

What does ANSI stand for in relation to the C programming language?

<p>American National Standards Institute (D)</p> Signup and view all the answers

Which IDE is recommended for beginners learning C programming?

<p>Code::Blocks (A)</p> Signup and view all the answers

Why might C be considered a low-level language?

<p>It directly interacts with hardware. (D)</p> Signup and view all the answers

Which file is recommended to install for setting up the Code::Blocks IDE with a compiler?

<p>mingw-setup.exe (B)</p> Signup and view all the answers

What is the purpose of the initializer in a for loop?

<p>It is evaluated once before the loop starts. (A)</p> Signup and view all the answers

What happens if the termination condition in a for loop evaluates to false?

<p>The loop will terminate. (A)</p> Signup and view all the answers

What is a common way to express an infinite loop in a for loop?

<p>for (; ;) { … } (A)</p> Signup and view all the answers

How can arithmetic expressions be utilized in a for loop?

<p>In both the initialization and increment sections. (A)</p> Signup and view all the answers

Which of the following for loops is equivalent to a while loop?

<p>for (expr1; expr2; expr3) { statement1; } (B)</p> Signup and view all the answers

Which part of a simple program is responsible for storing values?

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

Why must variables be declared before being assigned values?

<p>To allocate memory (A)</p> Signup and view all the answers

What is the correct assignment statement for a float variable named 'x'?

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

Which of the following variable names follows proper naming conventions in C?

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

How many characters should a variable name ideally have to ensure portability?

<p>31 (C)</p> Signup and view all the answers

In C, what is the purpose of the main body of a program?

<p>To perform calculations (B)</p> Signup and view all the answers

Which of the following statements correctly describes a constant in programming?

<p>Its value remains the same throughout the program. (B)</p> Signup and view all the answers

What characters are allowed in a C variable name?

<p>Letters, digits, and underscores (D)</p> Signup and view all the answers

Which operator is used for variable assignment in C?

<p>= (C)</p> Signup and view all the answers

What type of variable can hold a single character in C?

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

What does the atoi function do with a String argument?

<p>Converts it to an integer (D)</p> Signup and view all the answers

What does the printf statement output in the example with atoi when 'test2 333' is executed?

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

What is the primary purpose of the getchar function?

<p>To read a single character from input (A)</p> Signup and view all the answers

In a while loop, what happens if the expression evaluates to false?

<p>The loop skips to the end (D)</p> Signup and view all the answers

What will the following loop do: 'while (1) { putchar(c); c = getchar(); }'?

<p>Print characters until EOF is reached (D)</p> Signup and view all the answers

What error message is displayed if argc is less than 2 in the if statement example?

<p>error; must enter at least one argument! (D)</p> Signup and view all the answers

Which control statement is considered less favorable and typically avoided?

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

What is a primary difference between for loops and while loops?

<p>For loops use a specific structure that can be more concise (B)</p> Signup and view all the answers

What is the purpose of the break statement within loops?

<p>To exit the loop immediately (B)</p> Signup and view all the answers

In a do-while loop, what distinguishes it from a standard while loop?

<p>It executes the block before checking the condition (C)</p> Signup and view all the answers

What is the correct way to calculate the ratio of female to male students?

<p>Ratio = female_students / male_students (D)</p> Signup and view all the answers

What is the first step in the structure of a C program?

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

Which of the following is NOT a valid variable declaration in C?

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

What must always follow variable declarations in a C program?

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

Which statement is true about C program statements?

<p>Statements must end with a semicolon. (B)</p> Signup and view all the answers

What is the purpose of the printf function in C?

<p>To send output to the standard output device (A)</p> Signup and view all the answers

Which of the following statements about formatting and whitespace in C is correct?

<p>Blank lines are ignored by the compiler. (A)</p> Signup and view all the answers

Which of the following represents an assignment expression in C?

<p>x = 5 + y; (A)</p> Signup and view all the answers

What does the statement 'int g = 1, h, k = 3;' signify?

<p>Variables g and k are initialized with specified values. (B)</p> Signup and view all the answers

Which of the following is NOT a feature of executable statements in C?

<p>They must begin with a variable declaration. (A)</p> Signup and view all the answers

Flashcards

For loop

A loop structure that iterates over a sequence of values, typically based on a counter variable.

Initializer (For loop)

The expression evaluated once at the start of the loop, setting up the loop counter or initial conditions.

Termination condition (For loop)

The expression evaluated at the beginning of every iteration. If it evaluates to false, the loop ends.

Increment expression (For loop)

The expression evaluated at the end of every iteration. Typically, increments or modifies the control variable used for iteration.

Signup and view all the flashcards

Infinite loop (For loop)

A for loop that continues indefinitely, as the termination condition is always true.

Signup and view all the flashcards

String

A sequence of characters enclosed within double quotes. It can include letters, numbers, symbols, and spaces.

Signup and view all the flashcards

Newline character (\n)

A special character used to mark the end of a line. It tells the compiler to start a new line.

Signup and view all the flashcards

Integer Variable

A specific type of variable that can store whole numbers (integers) only.

Signup and view all the flashcards

Double Variable

A data type that can store numbers with decimal points.

Signup and view all the flashcards

Program Body

A code block that contains the core logic of your program.

Signup and view all the flashcards

Variable Declarations

Statements that define variables and their types within the program.

Signup and view all the flashcards

Executable Statements

Lines of code that perform specific actions within the program.

Signup and view all the flashcards

printf()

A function that sends output to the terminal screen.

Signup and view all the flashcards

Assignment statement

An instruction that assigns a value to a variable.

Signup and view all the flashcards

Semicolon (;)

A special symbol that separates individual statements in C code.

Signup and view all the flashcards

atoi()

Converts a string argument to an integer.

Signup and view all the flashcards

getchar()

Reads a single character from the standard input stream.

Signup and view all the flashcards

putchar()

Writes a single character to the standard output stream.

Signup and view all the flashcards

while loop

A loop that continues to execute as long as a specified condition is true (non-zero).

Signup and view all the flashcards

if statement

A block of code that executes only if a specified condition is true (non-zero).

Signup and view all the flashcards

switch statement

A control structure that allows for multiple branches of code execution based on a value.

Signup and view all the flashcards

do-while loop

A loop that executes a block of code at least once, and then continues as long as a specified condition is true (non-zero).

Signup and view all the flashcards

goto statement

A jump to a specific location in code.

Signup and view all the flashcards

break statement

Used to terminate a loop or switch statement.

Signup and view all the flashcards

char

A variable that stores a single character, like 'A' or '!' or '$'. It uses one byte of memory.

Signup and view all the flashcards

int

A variable that holds a value that can be a whole number, including negative, positive, and zero. It's a type of integer.

Signup and view all the flashcards

float

A variable that stores a number with a decimal point, like 3.14 or -5.8. It uses more memory than an 'int' because it has to store the decimal.

Signup and view all the flashcards

double

A variable that stores a number with even greater precision than a 'float'. It can handle larger numbers and decimal points.

Signup and view all the flashcards

Variable Assignment

Process of giving a variable a particular value, like assigning '30' to a variable called 'age'.

Signup and view all the flashcards

Variable Name

A name given to a variable, like 'age' or 'customerName'.

Signup and view all the flashcards

Variable

A special storage unit in a program that stores data. It's like a box that can hold different values over the course of a program's run.

Signup and view all the flashcards

Program Structure

Programs contain at least these three parts: declarations (create variables), initialization (give initial values), and the main body (where the program runs).

Signup and view all the flashcards

Constant

A value that stays the same throughout the program's execution, like a fixed number like 'Pi'.

Signup and view all the flashcards

What is C?

C is a general-purpose programming language created by Dennis Ritchie at Bell Laboratories in 1972. It's widely used despite its age and is strongly associated with the UNIX operating system.

Signup and view all the flashcards

Why learn C?

C is a popular language, it's quick (compiled), and its syntax is similar to other popular languages like Java and Python, making it easier to learn them afterwards.

Signup and view all the flashcards

What's the difference between C and C++?

C++ evolved from C and shares a similar syntax. The main difference is that C++ supports classes and objects, while C doesn't.

Signup and view all the flashcards

What is C programming language?

C is a structured programming language that's relatively low-level and portable, meaning it can be used on different systems. Many popular software tools are written in C, and it has influenced other languages like Java, C++, and Perl.

Signup and view all the flashcards

What is an IDE and why is it used?

An IDE (Integrated Development Environment) is used to both edit and compile your C code. Some popular options are Code::Blocks, Eclipse, and Visual Studio. They are free and allow you to debug your code too.

Signup and view all the flashcards

What is Code::Blocks and where can I get it?

Code::Blocks is an IDE that is recommended for beginners to start with, and you can download the latest version from their official website at http://www.codeblocks.org/. It includes a text editor and a compiler.

Signup and view all the flashcards

Is C object-oriented?

C is not object-oriented, meaning it doesn't directly use classes and objects. However, its successor, C++, is object-oriented. Even though it's not object-oriented, C is still a valuable language.

Signup and view all the flashcards

What does the ANSI part refer to?

The ANSI (American National Standards Institute) defines a standardized version of C, ensuring portability across different systems. This standardization makes it easier for developers to share and run their C code.

Signup and view all the flashcards

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 and argv 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 to while 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 in switch 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.

Quiz Team

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.

More Like This

IT Fundamentals Quiz
12 questions

IT Fundamentals Quiz

InnocuousDieBrücke avatar
InnocuousDieBrücke
Introduction to IT Code 402 Part A
5 questions
Use Quizgecko on...
Browser
Browser