Podcast
Questions and Answers
Which programming paradigm does the C language primarily support?
Which programming paradigm does the C language primarily support?
- Procedural programming (correct)
- Logic programming
- Object-oriented programming
- Functional programming
In what year was the C programming language developed?
In what year was the C programming language developed?
- 1985
- 1969
- 1972 (correct)
- 1978
Which operating system was primarily developed using the C programming language?
Which operating system was primarily developed using the C programming language?
- Windows
- UNIX (correct)
- macOS
- Android
Which of the following features is NOT supported by the C programming language?
Which of the following features is NOT supported by the C programming language?
What is the correct file extension for a C program source file?
What is the correct file extension for a C program source file?
Which of the following is an Integrated Development Environment (IDE) commonly used for C/C++ development?
Which of the following is an Integrated Development Environment (IDE) commonly used for C/C++ development?
Which of the following is a C/C++ compiler commonly used on Linux systems?
Which of the following is a C/C++ compiler commonly used on Linux systems?
Which of the following is a feature of C++ but NOT C?
Which of the following is a feature of C++ but NOT C?
What is the purpose of the #include
directive in a C program?
What is the purpose of the #include
directive in a C program?
Which of the following is the correct syntax to print output to the console in C?
Which of the following is the correct syntax to print output to the console in C?
What is the purpose of the return 0;
statement at the end of the main()
function in a C program?
What is the purpose of the return 0;
statement at the end of the main()
function in a C program?
Which of the following is the correct function to read formatted input from the keyboard in C?
Which of the following is the correct function to read formatted input from the keyboard in C?
During the compilation process, what is the role of the preprocessor?
During the compilation process, what is the role of the preprocessor?
Which stage of compilation translates assembly code into machine code?
Which stage of compilation translates assembly code into machine code?
What is the main function of the linker in the compilation process?
What is the main function of the linker in the compilation process?
What does the term 'preprocessing' refer to in the context of C compilation?
What does the term 'preprocessing' refer to in the context of C compilation?
What is the role of the compilation stage in the C compilation process?
What is the role of the compilation stage in the C compilation process?
What is the result of the assembly stage in C compilation?
What is the result of the assembly stage in C compilation?
What is the purpose of the linker stage in C compilation?
What is the purpose of the linker stage in C compilation?
What is the primary difference between scanf
and scanf_s
in C?
What is the primary difference between scanf
and scanf_s
in C?
What is the purpose of conversion specifiers in printf
?
What is the purpose of conversion specifiers in printf
?
Which conversion specifier is used in printf
to print a signed decimal integer?
Which conversion specifier is used in printf
to print a signed decimal integer?
Which conversion specifier is used in printf
to print an unsigned octal integer?
Which conversion specifier is used in printf
to print an unsigned octal integer?
Which conversion specifier is used in printf
to print a character?
Which conversion specifier is used in printf
to print a character?
In printf
, what is the purpose of a 'length modifier'?
In printf
, what is the purpose of a 'length modifier'?
In the context of format control strings for printf
, what is the purpose of flags?
In the context of format control strings for printf
, what is the purpose of flags?
Which escape sequence is used to insert a newline character in C?
Which escape sequence is used to insert a newline character in C?
Which escape sequence is used to insert a horizontal tab in C?
Which escape sequence is used to insert a horizontal tab in C?
What is the storage size of an int
data type in C?
What is the storage size of an int
data type in C?
What is the range of values for a signed char
data type in C?
What is the range of values for a signed char
data type in C?
According to operator precedence in C, which operation is evaluated first in the expression (a + b) * c
?
According to operator precedence in C, which operation is evaluated first in the expression (a + b) * c
?
In C, what is the meaning of the &&
operator?
In C, what is the meaning of the &&
operator?
In C, what is the purpose of the |
operator?
In C, what is the purpose of the |
operator?
What is the result of the bitwise AND operation between 5 (0101 in binary) and 3 (0011 in binary)?
What is the result of the bitwise AND operation between 5 (0101 in binary) and 3 (0011 in binary)?
What is the result of the bitwise XOR operation between 12 (1100 in binary) and 5 (0101 in binary)?
What is the result of the bitwise XOR operation between 12 (1100 in binary) and 5 (0101 in binary)?
What is the effect of the left shift operator <<
?
What is the effect of the left shift operator <<
?
What does the bitwise complement operator ~
do?
What does the bitwise complement operator ~
do?
In the given code, what will the program count until before terminating? EOF (ctrl + z on windows, ctrl+d on linux and mac)
In the given code, what will the program count until before terminating? EOF (ctrl + z on windows, ctrl+d on linux and mac)
Flashcards
What is C?
What is C?
A general-purpose, procedural programming language.
How are C programs written?
How are C programs written?
Text files with .c
extension.
What is a Compiler?
What is a Compiler?
Translates source code to machine code.
Compilation in C vs. C++
Compilation in C vs. C++
Signup and view all the flashcards
C++ paradigm
C++ paradigm
Signup and view all the flashcards
What is #include <stdio.h>?
What is #include <stdio.h>?
Signup and view all the flashcards
What is int main()
?
What is int main()
?
Signup and view all the flashcards
What does printf()
do?
What does printf()
do?
Signup and view all the flashcards
What does scanf()
do?
What does scanf()
do?
Signup and view all the flashcards
What does %d conversion specifier do?
What does %d conversion specifier do?
Signup and view all the flashcards
What is Preprocessing?
What is Preprocessing?
Signup and view all the flashcards
What are preprocessor commands?
What are preprocessor commands?
Signup and view all the flashcards
What is Compilation?
What is Compilation?
Signup and view all the flashcards
What is Assembly?
What is Assembly?
Signup and view all the flashcards
What is Linking?
What is Linking?
Signup and view all the flashcards
What does ' escape sequence do?
What does ' escape sequence do?
Signup and view all the flashcards
What does " escape sequence do?
What does " escape sequence do?
Signup and view all the flashcards
What does ? escape sequence do?
What does ? escape sequence do?
Signup and view all the flashcards
What does \a escape sequence do?
What does \a escape sequence do?
Signup and view all the flashcards
What does \n escape sequence do?
What does \n escape sequence do?
Signup and view all the flashcards
scanf_s() arguments
scanf_s() arguments
Signup and view all the flashcards
() precedence
() precedence
Signup and view all the flashcards
= precedence
= precedence
Signup and view all the flashcards
Bitwise AND (&)
Bitwise AND (&)
Signup and view all the flashcards
Bitwise OR (|)
Bitwise OR (|)
Signup and view all the flashcards
Bitwise XOR (^)
Bitwise XOR (^)
Signup and view all the flashcards
Left shift (<<)
Left shift (<<)
Signup and view all the flashcards
Right shift (>>)
Right shift (>>)
Signup and view all the flashcards
Bitwise complement (~)
Bitwise complement (~)
Signup and view all the flashcards
Study Notes
- C is a general-purpose, procedural programming language.
- It was developed in 1972 to develop the UNIX operating system.
- C doesn't support OOP, meaning no polymorphism, inheritance, or encapsulation.
- C programs are written in plain text files with the extension ".c".
C/C++ Compilers and IDEs
- Many C/C++ compilers and IDEs exist.
- IDEs include Code::blocks (Windows/Linux/MacOS), Visual Studio (Windows), and Dev-C++ (Windows).
- Compilers include GCC (Linux), MinGW (Minimalist GNU for Windows), and Clang (OS X).
- There have been four standard revisions: C++11, C++14, and C++17
C vs C++
- C uses procedural programming.
- C does not support polymorphism, encapsulation, and inheritance.
- C does not support function and operator overloading.
- C lacks namespace features
- C does not have virtual and friend functions
- C uses scanf for input and printf for output.
- C uses malloc() and free() for memory allocation/deallocation.
- C++ uses both procedural and OOP (Hybrid) programming.
- C++ supports polymorphism, encapsulation, and inheritance.
- C++ supports function and operator overloading.
- C++ uses the namespace feature.
- C++ supports virtual and friend functions.
- C++ uses cin for input and cout for output.
- C++ uses new and delete for memory allocation/deallocation.
C++ vs Java
- C++ compiles to machine code.
- C++ supports pointers and references.
- C++ utilizes manual garbage collection.
- C++ offers operator and method overloading.
- C++ supports multiple inheritance.
- C++ supports structures and unions.
- C++ provides access specifiers when inheriting from a class.
- Java compiles to byte code
- Java doesn't support pointers
- Java utilizes automatic garbage collection.
- Java does not have operator overloading.
- Java uses single inheritance.
- Java has no support for structures and unions.
- Java, access specifiers are not supported when inheriting.
First C Example
- The statement
#include <stdio.h>
is a directive to the C preprocessor. - It tells the preprocessor to include the contents of the standard input/output header (<stdio.h>) in the program.
#include
is similar toimport
in Java but the code is copied and added to the current file, increasing its size.- Every program in C contains one or more functions, one of them must be the main function.
- The program begins executing with the main() function.
- The returning value of the main function is an integer.
- The statement
printf("Welcome to CMPS270! \n");
prints to the standard output.
Compiling Stages
- Compilation of C code involves four stages: preprocessing, compilation, assembly, and linking.
- Preprocessing is the first stage of compilation.
- Lines starting with a # are interpreted by the preprocessor as preprocessor commands.
- These commands form a simple macro language with its own syntax.
- It reduces repetition in source code
- Compilation translates the preprocessed code to assembly instructions specific to the target processor architecture.
- It forms intermediate, human-readable language.
- Some compilers support an integrated assembler that directly generates machine code.
- Assembly translates assembly instructions into machine code or object code using an assembler.
- The output is the actual instructions for the target processor.
- An object file with the extension .obj is created.
- Linking: The object code, generated in the previous stage, is raw machine instructions that the processor understands.
- The linker arranges pieces of object code and adds pieces for library functions used by the program.
- The result of this stage is the final executable program.
Input / Output
scanf
reads input data from the standard input stream (keyboard).printf
outputs data to the standard output stream (screen).printf
contains a format control string that describes the format of the output.
Printf Format Control String
- Possible format control string consists of conversion specifiers (like %d, %f, %c, %s), flags (like +, -, 0), field widths, precisions, and literal characters.
- Possible formats include rounding floating-point values to a specific number of decimal places, aligning numbers in a column, and output justification (right / left).
Integer Conversion Specifiers
- d: Display as a signed decimal integer.
- i: Display as a signed decimal integer. The i and d specifiers are different when used with
scanf
. - o: Display as an unsigned octal integer.
- u: Display as an unsigned decimal integer.
- x or X: Display as an unsigned hexadecimal integer. X causes the digits 0-9 and the uppercase letters A-F to be used in the display and x causes the digits 0-9 and the lowercase letters a-f to be used in the display.
- h, l, or ll: Placed before any integer conversion specifier, these indicate that a short, long, or long long integer is displayed, respectively. They are called length modifiers.
Conversion Specifiers
- e or E: Display a floating-point value in exponential notation.
- f or F: Display floating-point values in fixed-point notation (F is supported in the Microsoft Visual C++ compiler in Visual Studio 2015 and higher).
- g or G: Display a floating-point value in either the floating-point form f or the exponential form e (or E), based on the magnitude of the value.
- L: Place before any floating-point conversion specifier to indicate that a long double floating-point value should be displayed.
- p: Display a pointer value in an implementation-defined manner.
- %: Display the percent character.
- c: Display a character argument.
- s: Displays a string (array of characters).
Format String Flags
- - (minus sign): Left justify the output within the specified field.
-
- Display a plus sign preceding positive values and a minus sign preceding negative values.
- space Print a space before a positive value not printed with the + flag.
- #: Prefix 0 to the output value when used with the octal conversion specifier o.
- Prefix 0x or 0X to the output value when used with the hexadecimal conversion specifiers x or X.
- Force a decimal point for a floating-point number printed with e, E, f, g or G that doesn't contain a fractional part.
- (Normally the decimal point is printed only if a digit follows it.) For g and G specifiers, trailing zeros are not eliminated.
- 0 (zero) Pad a field with leading zeros.
Escape Sequences
- ': Output the single quote (') character.
- ": Output the double quote (") character.
- ?: Output the question mark (?) character.
- \: Output the backslash () character.
- \a: Cause an audible (bell) or visual alert (typically, flashing the window in which the program is running).
- \b: Move the cursor back one position on the current line.
- \f: Move the cursor to the start of the next logical page.
- \n: Move the cursor to the beginning of the next line.
- \r: Move the cursor to the beginning of the current line.
- \t: Move the cursor to the next horizontal tab position.
- \v: Move the cursor to the next vertical tab position.
Scanf_s
- scanf(): reads input from the standard input. If the input exceeds the variable's size, it overrides the adjacent memory.
- scanf_s(): a safer function takes width specification, memory address, buffer size, and terminating character.
- scanf_s() checks the size of the buffer and prevents writing to the buffer if the input is too large.
C Data Types
- char: 1 byte, range: -128 to 127 or 0 to 255.
- unsigned char: 1 byte, range: 0 to 255.
- signed char: 1 byte, range: -128 to 127.
- int: 2 or 4 bytes, range: -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647.
- unsigned int: 2 or 4 bytes, range: 0 to 65,535 or 0 to 4,294,967,295.
- short: 2 bytes, range: -32,768 to 32,767.
- unsigned short: 2 bytes, range: 0 to 65,535.
- long: 4 bytes, range: -2,147,483,648 to 2,147,483,647.
- unsigned long: 4 bytes, range: 0 to 4,294,967,295.
C / C++ Operators
- Parentheses (): Evaluated first.
- Multiplication (*), Division (/), Remainder (%) Evaluated second from left to right.
- Addition (+), Subtraction (-) Evaluated third from left to right.
- Assignment (=) Evaluated last.
Relational Operators
- Relational operators compare two values and return a Boolean result.
- Equality operators check for equality or inequality.
- Logical operators (&&, ||, !) perform logical AND, OR, and NOT operations.
Bitwise Operators
- Bitwise operators:
- AND (&): Sets each bit in the result to 1 if both operands are 1, otherwise 0.
- inclusive OR (|): Sets each bit to 1 if either (or both) operand(s) is 1.
- exclusive OR (^): Sets each bit to 1 if exactly one operand is 1; otherwise, it sets the bit to 0.
- Left shift (<<): Shifts bits to the left by the number specified.
- Right shift (>>): Shifts bits to the right by the number specified.
- Complement (~): Sets all 0 bits to 1 and all 1 bits to 0.
- Bitwise AND, OR, and XOR compare their operands bit by bit.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.