Podcast
Questions and Answers
Which of the following is NOT a basic data type in C?
Which of the following is NOT a basic data type in C?
- double
- const (correct)
- float
- char
What is the primary characteristic of a pointer in C?
What is the primary characteristic of a pointer in C?
- It holds the memory address of another variable. (correct)
- It is used exclusively for string data.
- It stores the value of variables directly.
- It automatically manages memory allocation.
What is the typical size of an 'int' data type in C?
What is the typical size of an 'int' data type in C?
- 2 bytes
- 8 bytes
- 16 bytes
- 4 bytes (correct)
Which data type allows multiple members to share the same memory location?
Which data type allows multiple members to share the same memory location?
Which of the following correctly defines a double data type variable?
Which of the following correctly defines a double data type variable?
How does the const
keyword affect a variable in C?
How does the const
keyword affect a variable in C?
What does the keyword 'void' signify in a function's return type?
What does the keyword 'void' signify in a function's return type?
Which statement about arrays in C is accurate?
Which statement about arrays in C is accurate?
Which statement about local variables is true?
Which statement about local variables is true?
Which of the following describes derived data types?
Which of the following describes derived data types?
What is the maximum size for a 'short' data type typically in C?
What is the maximum size for a 'short' data type typically in C?
What is the purpose of the #define
directive in C?
What is the purpose of the #define
directive in C?
What is the purpose of the 'const' keyword in variable declaration?
What is the purpose of the 'const' keyword in variable declaration?
What is a key requirement of the members of a structure in C?
What is a key requirement of the members of a structure in C?
Which of the following statements about signed and unsigned types is true?
Which of the following statements about signed and unsigned types is true?
Which data type would be appropriate for storing the height of a person in meters?
Which data type would be appropriate for storing the height of a person in meters?
What is the main difference between variable definition and declaration?
What is the main difference between variable definition and declaration?
What is the scope of a global variable in a C program?
What is the scope of a global variable in a C program?
How are variables declared in C?
How are variables declared in C?
Which of the following pairs of identifiers would be treated as different by C due to case sensitivity?
Which of the following pairs of identifiers would be treated as different by C due to case sensitivity?
Which data type would be best for storing a single character?
Which data type would be best for storing a single character?
What is the lifetime of a local variable?
What is the lifetime of a local variable?
What must the main function return at the end of program execution?
What must the main function return at the end of program execution?
Which of the following correctly describes the purpose of 'int argc' in the main function?
Which of the following correctly describes the purpose of 'int argc' in the main function?
What does the escape sequence '\n' do in a C program?
What does the escape sequence '\n' do in a C program?
What is the correct syntax to declare a main function that accepts command-line arguments?
What is the correct syntax to declare a main function that accepts command-line arguments?
Which comment style allows for multiple lines in C code?
Which comment style allows for multiple lines in C code?
What will be the output of the following code: printf("Welcome\nto\nFallTerm!\n");?
What will be the output of the following code: printf("Welcome\nto\nFallTerm!\n");?
What is the role of the backslash '' in escape sequences?
What is the role of the backslash '' in escape sequences?
Which of the following is NOT a valid escape sequence?
Which of the following is NOT a valid escape sequence?
What does the declaration of a variable in C specify?
What does the declaration of a variable in C specify?
Which of the following correctly describes the scope of global variables?
Which of the following correctly describes the scope of global variables?
When a local variable is created, when is its memory allocated?
When a local variable is created, when is its memory allocated?
What is the primary distinction between variable definition and declaration in C?
What is the primary distinction between variable definition and declaration in C?
Which of the following types of variables is accessible throughout the entire program?
Which of the following types of variables is accessible throughout the entire program?
What happens to the lifetime of a local variable once the function it belongs to exits?
What happens to the lifetime of a local variable once the function it belongs to exits?
What is the purpose of specifying a data type when declaring a variable in C?
What is the purpose of specifying a data type when declaring a variable in C?
How does case sensitivity in C affect variable identifiers?
How does case sensitivity in C affect variable identifiers?
What does the variable 'institutionID' represent in the example provided?
What does the variable 'institutionID' represent in the example provided?
Which statement correctly describes 'studentID' in the resizeClass function?
Which statement correctly describes 'studentID' in the resizeClass function?
What is the significance of data types in C programming?
What is the significance of data types in C programming?
In C, how many bytes does a float typically occupy?
In C, how many bytes does a float typically occupy?
Which data type is used to represent real numbers with greater precision in C?
Which data type is used to represent real numbers with greater precision in C?
What does the keyword 'void' indicate when used in a function declaration?
What does the keyword 'void' indicate when used in a function declaration?
Which of the following statements about local variables is incorrect?
Which of the following statements about local variables is incorrect?
Which statement about basic data types is true regarding their size?
Which statement about basic data types is true regarding their size?
What is the default precision for the %f format specifier in the printf function?
What is the default precision for the %f format specifier in the printf function?
What would be the output of the following printf function: printf("x=%4.1f, y=%7.2f", 15.231, 65.875948);?
What would be the output of the following printf function: printf("x=%4.1f, y=%7.2f", 15.231, 65.875948);?
In the example with scanf("%3f%4f", &a, &b), what value will be stored in variable 'a' if the input is 5.965.87?
In the example with scanf("%3f%4f", &a, &b), what value will be stored in variable 'a' if the input is 5.965.87?
What determines the output's right justification in printf when using field width?
What determines the output's right justification in printf when using field width?
How many characters will the output 'b' have if it is formatted using printf with a field width of 4 (e.g., b=5)?
How many characters will the output 'b' have if it is formatted using printf with a field width of 4 (e.g., b=5)?
Which of the following printf format specifiers correctly formats a floating-point number to display one digit after the decimal point and minimum width of 4?
Which of the following printf format specifiers correctly formats a floating-point number to display one digit after the decimal point and minimum width of 4?
If the scanf function scans the input string '1234.56', what value will be assigned to 'b' when using scanf("%3f%4f", &a, &b)?
If the scanf function scans the input string '1234.56', what value will be assigned to 'b' when using scanf("%3f%4f", &a, &b)?
Which aspect of control flow in C does not involve looping?
Which aspect of control flow in C does not involve looping?
What is the primary characteristic of a struct in C?
What is the primary characteristic of a struct in C?
What does the 'long long' data type guarantee in C?
What does the 'long long' data type guarantee in C?
Which of the following statements about pointers is accurate?
Which of the following statements about pointers is accurate?
What is a characteristic feature of a union in C?
What is a characteristic feature of a union in C?
What is the effect of using the 'const' keyword in a declaration?
What is the effect of using the 'const' keyword in a declaration?
How are array sizes determined in C?
How are array sizes determined in C?
What type of variable can a pointer in C hold?
What type of variable can a pointer in C hold?
What is the result of using the '#define' directive incorrectly, as in '#define MAX 10;' with a semicolon?
What is the result of using the '#define' directive incorrectly, as in '#define MAX 10;' with a semicolon?
What does the 'scanf' function require to store input values in the variables specified?
What does the 'scanf' function require to store input values in the variables specified?
What will be the value of the variable 'term' after executing 'scanf("%d:%f", &marks, &term);' with the input '1500:20.5'?
What will be the value of the variable 'term' after executing 'scanf("%d:%f", &marks, &term);' with the input '1500:20.5'?
How are macros defined with arguments expanded in C?
How are macros defined with arguments expanded in C?
What value will 'a' and 'b' hold after executing 'scanf("%2d%3d", &a, &b);' with input '6903901'?
What value will 'a' and 'b' hold after executing 'scanf("%2d%3d", &a, &b);' with input '6903901'?
Which of the following statements is true regarding the usage of the 'const' keyword?
Which of the following statements is true regarding the usage of the 'const' keyword?
What is the result of evaluating the macro 'SUM(4, 5)' using the definition '#define SUM(x, y) ((x) + (y))'?
What is the result of evaluating the macro 'SUM(4, 5)' using the definition '#define SUM(x, y) ((x) + (y))'?
What will the statement 'printf("Max students: %d\n", MAX_STUDENTS);' output given 'MAX_STUDENTS' is defined as 500?
What will the statement 'printf("Max students: %d\n", MAX_STUDENTS);' output given 'MAX_STUDENTS' is defined as 500?
Flashcards
Array
Array
A collection of elements of the same data type.
Pointer
Pointer
Holds the memory address of another variable.
Structure (struct)
Structure (struct)
Groups variables of different types into a single unit.
Union
Union
Signup and view all the flashcards
Signed/Unsigned
Signed/Unsigned
Signup and view all the flashcards
Short/Long
Short/Long
Signup and view all the flashcards
long long
long long
Signup and view all the flashcards
const
const
Signup and view all the flashcards
Global variable
Global variable
Signup and view all the flashcards
Local variable
Local variable
Signup and view all the flashcards
Data Type (int)
Data Type (int)
Signup and view all the flashcards
Data Type (char)
Data Type (char)
Signup and view all the flashcards
Data Type (float)
Data Type (float)
Signup and view all the flashcards
Data Type (double)
Data Type (double)
Signup and view all the flashcards
Data Type (void)
Data Type (void)
Signup and view all the flashcards
Variable Scope
Variable Scope
Signup and view all the flashcards
Variable Declaration
Variable Declaration
Signup and view all the flashcards
Variable Definition
Variable Definition
Signup and view all the flashcards
Variable Lifetime
Variable Lifetime
Signup and view all the flashcards
Data Type (int, char, float, double)
Data Type (int, char, float, double)
Signup and view all the flashcards
Case Sensitivity (programming)
Case Sensitivity (programming)
Signup and view all the flashcards
Main Function
Main Function
Signup and view all the flashcards
Command-Line Arguments
Command-Line Arguments
Signup and view all the flashcards
What does return 0;
indicate?
What does return 0;
indicate?
Signup and view all the flashcards
Escape Sequence
Escape Sequence
Signup and view all the flashcards
What is \n
?
What is \n
?
Signup and view all the flashcards
Variable
Variable
Signup and view all the flashcards
Declare a Variable
Declare a Variable
Signup and view all the flashcards
Scope
Scope
Signup and view all the flashcards
Lifetime
Lifetime
Signup and view all the flashcards
Variable Initialization
Variable Initialization
Signup and view all the flashcards
Case Sensitivity
Case Sensitivity
Signup and view all the flashcards
int Data Type
int Data Type
Signup and view all the flashcards
char Data Type
char Data Type
Signup and view all the flashcards
float Data Type
float Data Type
Signup and view all the flashcards
double Data Type
double Data Type
Signup and view all the flashcards
void Data Type
void Data Type
Signup and view all the flashcards
Data Type
Data Type
Signup and view all the flashcards
What is an array?
What is an array?
Signup and view all the flashcards
What does a pointer store?
What does a pointer store?
Signup and view all the flashcards
What is a structure?
What is a structure?
Signup and view all the flashcards
What is a union?
What is a union?
Signup and view all the flashcards
What is the purpose of the const
keyword?
What is the purpose of the const
keyword?
Signup and view all the flashcards
What is a signed integer?
What is a signed integer?
Signup and view all the flashcards
What is an unsigned integer?
What is an unsigned integer?
Signup and view all the flashcards
What is the difference between short
and long
integers?
What is the difference between short
and long
integers?
Signup and view all the flashcards
#define vs const
#define vs const
Signup and view all the flashcards
printf Function
printf Function
Signup and view all the flashcards
Control String
Control String
Signup and view all the flashcards
Macro with Arguments
Macro with Arguments
Signup and view all the flashcards
Field Width
Field Width
Signup and view all the flashcards
Nesting of Macros
Nesting of Macros
Signup and view all the flashcards
Precision (For Floats)
Precision (For Floats)
Signup and view all the flashcards
scanf control string
scanf control string
Signup and view all the flashcards
scanf Function
scanf Function
Signup and view all the flashcards
scanf Example: int & float
scanf Example: int & float
Signup and view all the flashcards
scanf Example: String
scanf Example: String
Signup and view all the flashcards
Control Flow
Control Flow
Signup and view all the flashcards
scanf Example: Field Width Specifier
scanf Example: Field Width Specifier
Signup and view all the flashcards
Conditionals
Conditionals
Signup and view all the flashcards
What does return 0;
signify?
What does return 0;
signify?
Signup and view all the flashcards
Study Notes
Course Information
- Course Title: C Programming
- Course Code: CST8234
- Week: 2
- Topic: Basics of the language
Objectives
- Write simple C programs
- Use I/O statements
- Understand fundamental data types
- Write simple decision-making statements
- Learn about control specifiers
- Understand macros
- Introduction to arrays
Basics of the C Language
- The
main
function is the entry point of a C program. - Using other files and libraries (e.g.,
#include <stdio.h>
). - C program structure: preprocessor directives, function definitions, statements and expressions.
- Variables
- Control Flow (conditionals and loops)
- Functions
Typical C Program Structure
- Preprocessor directives: lines beginning with
#
(e.g.,#include
). - Function definitions: including the
main
function and other functions. - Statements and expressions: actual code to perform operations.
Example of a Typical C Program
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(5, 3);
printf("The result is %d\n", result);
return 0;
}
#include Directive
- Used to include the contents of a file within another file.
- Useful for including libraries (e.g.,
stdio.h
) and user-defined header files. - Syntax:
#include <filename.h>
: include from a standard library.#include "filename.h"
: include from a local directory.
How #include Works
- Preprocessor stage: replaces the
#include
directive with the contents of the specified file before compilation. - Inclusion of content: the compiler processes included content as part of the original file.
Avoiding Multiple Inclusions
- Use include guards (e.g.,
#ifndef
,#define
,#endif
) to prevent multiple inclusions of the same header file.
The main
Function (Example)
#include <stdio.h>
int main() {
printf("Welcome to C!\n");
return 0;
}
Variables
- Variables in C store data.
- They must be declared before use with a data type.
- Example:
int age = 25;
,char initial = 'A';
. - Different data types:
int
,char
,float
,double
.
Variables Definition vs Declaration
- Definition: allocates memory and initializes a variable.
- Declaration: declares a variable without allocating memory.
Scope and Lifetime of Variables
- Global variables: accessible throughout the entire program.
- Local variables: accessible only within the function or block where they are declared.
Data Types
int
: whole numberschar
: single charactersfloat
: single-precision floating-point numbersdouble
: double-precision floating-point numbers
Derived Data Types
void
: absence of typearray
: collection of elements of the same type.pointer
: holds memory address of another variable.struct
: groups variables of different types.union
: similar to structure, but members share memory.
Modified Data Types
signed/unsigned int
: specify whether integers can be negative or not.short/long int
: modify integer size.long long
: an extended version oflong int
.
const Keyword
const
variables have values that cannot be changed after initialization.- Useful for defining constants (e.g., configuration parameters).
Macro
- Used to define macros or constants during the preprocessing stage.
- The
#define
directive is used to substitute text in the code with a literal value. - Example: macro
#define MAX_VALUE 100
.
const
vs #define
const:
has type safety, allocates memory.#define:
no type safety, no memory allocation.
Control Specifiers in scanf
and printf
scanf
reads input from the user,printf
displays output.- Control strings specify input/output formats.
- Use format specifiers (e.g.,
%d
for integers,%f
for floats,%s
for strings).
Functions
- Functions are fundamental building blocks in a C program.
- Function syntax:
<return type> <function name>(<parameters>)
. - Functions are reusable code blocks.
For Loop:
- Used for fixed iterations
While Loop:
- Used for iterations based on a condition
Do-while:
- The loop body is executed at least once.
Logical Operators
&&
: logical AND,||
: logical OR,!
: logical NOT
Relational Operators
- `==`, `!=`, `<`, `>`, `<=`, `>=`: Used to compare values and create conditions.
Ternary Operator
- A shorthand for if-else statements.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers the fundamentals of C programming language, focusing on writing simple C programs, understanding I/O statements, and fundamental data types. It also introduces control flow and arrays, providing essential skills for coding in C. Test your knowledge on these basic concepts with this quiz.