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.</p> Signup and view all the answers

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

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

    Which IDE is recommended for beginners learning C programming?

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

    Why might C be considered a low-level language?

    <p>It directly interacts with hardware.</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</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.</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.</p> Signup and view all the answers

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

    <p>for (; ;) { … }</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.</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; }</p> Signup and view all the answers

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

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

    Why must variables be declared before being assigned values?

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

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

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

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

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

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

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

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

    <p>To perform calculations</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.</p> Signup and view all the answers

    What characters are allowed in a C variable name?

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

    Which operator is used for variable assignment in C?

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

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

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

    What does the atoi function do with a String argument?

    <p>Converts it to an integer</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</p> Signup and view all the answers

    What is the primary purpose of the getchar function?

    <p>To read a single character from input</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</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</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!</p> Signup and view all the answers

    Which control statement is considered less favorable and typically avoided?

    <p>goto statements</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</p> Signup and view all the answers

    What is the purpose of the break statement within loops?

    <p>To exit the loop immediately</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</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</p> Signup and view all the answers

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

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

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

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

    What must always follow variable declarations in a C program?

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

    Which statement is true about C program statements?

    <p>Statements must end with a semicolon.</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</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.</p> Signup and view all the answers

    Which of the following represents an assignment expression in C?

    <p>x = 5 + y;</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.</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.</p> 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 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
    3 questions

    IT Fundamentals Quiz

    StrongestBowenite avatar
    StrongestBowenite
    IT Fundamentals Quiz
    12 questions

    IT Fundamentals Quiz

    InnocuousDieBrücke avatar
    InnocuousDieBrücke
    Use Quizgecko on...
    Browser
    Browser