Podcast
Questions and Answers
Which of the following code snippets will correctly print a single backslash character (\
) to the console in C?
Which of the following code snippets will correctly print a single backslash character (\
) to the console in C?
- `printf("\\");` (correct)
- `printf("\\");` (correct)
- `printf("\ ");`
- `printf("\b");`
An unsigned
6-bit integer can represent the same range of values as a signed
6-bit integer.
An unsigned
6-bit integer can represent the same range of values as a signed
6-bit integer.
False (B)
What is the purpose of the system("PAUSE");
command in a C program, and why is it often used?
What is the purpose of the system("PAUSE");
command in a C program, and why is it often used?
It pauses the program execution until the user presses a key, preventing the console window from closing immediately after the program finishes.
The __________
statement skips the current iteration of a loop and proceeds to the next iteration.
The __________
statement skips the current iteration of a loop and proceeds to the next iteration.
Match the following C code elements with their descriptions:
Match the following C code elements with their descriptions:
Which of the following actions will improve software speed?
Which of the following actions will improve software speed?
In C, the expression 100 > n > 20
is a valid way to check if the variable n
is between 20 and 100.
In C, the expression 100 > n > 20
is a valid way to check if the variable n
is between 20 and 100.
When determining if a number n
is prime, up to what integer should you check for divisibility?
When determining if a number n
is prime, up to what integer should you check for divisibility?
Flashcards
Printing Backslash
Printing Backslash
To print a backslash () in C, use two backslashes ().
\t in C
\t in C
Inserts a tab.
Unsigned Integer
Unsigned Integer
A data type that represents only non-negative numbers.
Signed Integer
Signed Integer
Signup and view all the flashcards
C Naming Rules
C Naming Rules
Signup and view all the flashcards
Continue Statement
Continue Statement
Signup and view all the flashcards
Break Statement
Break Statement
Signup and view all the flashcards
Do-While Loop
Do-While Loop
Signup and view all the flashcards
Study Notes
- To print a backslash, use
\\
- To print a percentage sign, use
%%
\t
creates a tab space\n
creates a new linesystem("PAUSE");
prevents the program from quitting immediately, waiting for user input instead
Program Initialization
#include <stdio.h>
is included at the start of every program, allowing functions likeprintf
andscanf
to be usedreturn 0;
is used before ending the main program, confirming that everything ran successfully
Integer Data Types
- If an integer data type is 6-bit, it supports 64 unique combinations
- An unsigned integer can only represent non-negative values, its values range from 0 to 2n-1
- A 6-bit unsigned integer's range is 0 to 63
- A signed integer can represent both positive and negative values, its values range from -2n-1 to 2n-1-1
- A 6-bit signed integer's range is -32 to 31
Software Optimization
- Software speed is improved when HDD access is reduced, memory locality is maximized, and CPU computations are minimized
Character Encoding
- High voltage is not necessarily represented by "1"
- ASCII is 8 bit, and can represent 256 unique characters
- Unicode supports all of the world's languages, representing over a million unique characters
Assembly Language
- Assembly language is a technical form of high-level code, reflecting CPU operations, but is platform dependent, and not portable
Code Execution
- A bug free piece of C code execution sequence goes like this: High-level C code compiles to assembly code, which compiles into machine code
Naming conventions
- C variable and function naming rules: only letters, digits, and underscores are allow
- Variables must begin with letters and cannot contain spaces
- Keywords are not allowed (e.g.,
for
,while
,int
) - C is case sensitive
Operators
- Cannot write
100 > n > 20
in C, use logical operators&&
(and)||
(or) - A ternary/conditional operator is formatted as:
(condition ? "if true print" : "if false print");
Switch Statements
- If
break;
is not added between each case of aswitch
statement, the code continues to execute the following cases until abreak
is encountered
Loops
break;
terminates the current loopcontinue;
skips the current iteration of the loop and moves to the next iteration of the loop
Prime Numbers
- To determine if a number is prime, check if the number is divisible by integers from 2, to the square root of the number
Functions
- Functions do not always need to return a value in C
do while
loop executes the loop at least once, even if the condition is false- In a function, parameters are transferred by value
Main Function
- The main function cannot be called in the program, it calls other functions within it
- All functions are not required to be called by the main function
Function Parameters
- Given
long func(int n, int i)
is a function, an invalid call would befunc1("5", 3)
because the function takes integer values - Valid calls include
func1(5,10)
orlong result = func1(3,2)
andint result = func1(7,4)
Data Types
- The result of
5 / 2
in C is2
Double
orlong float
data types can store the largest value- The default return type of
main()
in C isint
- Variables defined as
float
use more memory thanint
variables - The
switch
statement cannot check conditions using relational operators const
keyword is used to define a constant variable in Cscanf
takes input from the user- Converting a float to an int using
(int)
is called type casting
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.