Can an identifier start with a digit?
Click to see answer
No, it must not start with a digit.
Click to see question
Can an identifier start with a digit?
No, it must not start with a digit.
Why should names with all uppercase letters be avoided?
They are usually reserved for named constants.
What is the syntax for declaring multiple variables of the same type?
type2 var1, var2, …, varN;
Which of the following is a valid identifier: $ abc?
No, it is not a valid identifier.
What is the second topic in the outline?
Variables and Assignment Operators.
What is a string constant in the context of the printf() function?
A piece of text enclosed in quotes, such as "Hello, world!\n".
What is an identifier in a program?
A name used to identify variables, functions, etc.
Can a string constant span multiple lines?
No, a string constant cannot span multiple lines.
What is the purpose of comments in C?
They are used for documentation aid and are ignored by the compiler.
What is the output of the string constant 'The first line . The second line.'?
The first line . The second line.
What are the two styles of comments in C?
Block comments (/* ... */) and line comments (//).
What are predefined identifiers in C?
Identifiers that have already been used as names for standard usages, such as main, printf, and scanf.
What does the type of a variable determine?
What kind of values the variable can hold.
What is a key guideline for naming conventions in programming?
Names should be meaningful.
What happens if a program contains syntax errors?
It cannot be compiled into an executable program.
What will happen if a string constant is not enclosed in double quotes?
The C compiler will not treat the text as a string constant.
What is the syntax for assigning a value to a variable?
variable = expression;
What will cause a C program to fail to compile?
Using printf(Hello, world! ); without double quotes.
Give an example of an expression that can be assigned to a variable.
100, someVariable, or 200 + var1 * var2.
What data type is used for 'side', 'perimeter', and 'area' in the program?
int (integer).
What is the purpose of the 'main' function in a C program?
It serves as the entry point for program execution.
Is tab a valid identifier?
Yes, it is a valid identifier.
What is a reserved word?
A word that has a special meaning in a programming language and cannot be used as a variable name.
What characters can an identifier contain?
Alphabets (A-Z, a-z), digits (0-9), and the underscore character (_).
What is an expression in the context of variable assignment?
An expression is made up of values and operators that can be evaluated to a value in the program.
What data type is used to store the value of pi in the example?
double
What does the variable side represent in the program?
It represents the length of one side of a square.
What function is used to prompt the user for input?
printf
Which function is used to read an integer from the user?
scanf
What are the two output statements in the provided C program?
"Hello, world!" and "Hello, universe!"
What value is assigned to 'side' in the program?
What value is assigned to 'side' in the code?
The value assigned to 'side' is 3.
What is the output of the program for the variable 'area'?
The output for 'area' will be 9.
What is the example output used in the printf() function?
"Hello, world!\n"
What must a string constant be enclosed by in C?
A pair of double-quote characters (" ").
How does printf("Hello world!\n"); differ from printf("Side : %d\n", side);?
The first prints a static string, while the second prints a formatted string with a variable value.
What is a variable in C?
A variable holds a value, has a name, and a type.
What occurs when scanf() is called?
Execution is paused while scanf() waits for user input.
What happens when you assign an expression to a variable?
The value of the expression is copied to the variable.
What formula is used to calculate the area of a square in the program?
side * side.
What is the output of printf() with the format specifier %.6f for the value of pi?
3.141593
What is the purpose of including <stdio.h> in a C program?
To use input and output functions like printf().
What happens when scanf() encounters invalid input?
It won't work properly, for example, if a user enters an alphabet when an integer is expected.
What format specifier is used to read integers in scanf()?
%d
Is 1_1 a valid identifier?
No, it is not a valid identifier.
What must be done before using variables in a program?
Variables must be declared first.
What is the main error in the provided C code?
The function 'Printf' should be 'printf' (case sensitivity).
What is the syntax for declaring a single variable?
type1 var1;
Why can't computers follow malformed instructions?
Because they rely on correct syntax to execute commands.
What data type is used for the variables 'side', 'perimeter', and 'area'?
int (indicating they store integers).
What is the purpose of the program in Example 5.3?
To read two floating point numbers from the user.
What is the purpose of the 'main' function in a C program?
It serves as the entry point for program execution.
How is the perimeter of a square calculated in the program?
By multiplying 4 by the length of one side.
What functions are used for console input/output in C?
scanf() and printf().
What does the format string '%d%d' in scanf() indicate?
It tells scanf() to read two integers.
What does the program output after the user enters the integer 123?
num1 = 123
What is required between the two input values for scanf() to work correctly?
At least one whitespace character.
What does the variable 'side' represent in the code?
It represents the length of one side of a square.
What formula is used to calculate the area of the square?
Area = side * side.
What happens to the variables 'side', 'perimeter', and 'area' immediately after declaration?
Their values are undefined; they are uninitialized.
What is the purpose of variables in a program?
To store data.
How do you print a double quotation mark in a string constant?
Use the escaped sequence ".
What is syntax in programming languages?
A set of rules that defines the structure of the code, similar to grammar in the English language.
What does the format specifier %d indicate in printf?
It specifies that the corresponding expression's value should be printed as a decimal integer.
What operator is used to assign a value to a variable in C?
The assignment operator (=).
In the statement printf("Side : %d\n", side);, what does 'side' represent?
It is the expression whose value is supplied to the format string.
What library is included at the beginning of the C program?
<stdio.h>
What is the entry point of a C program?
The main() function.
What is the purpose of the assignment operator in C?
To assign a value to a variable.
What is an identifier in C?
A valid name for identifying things in the program.
What does expressing numeric and string constants involve?
Defining fixed values in the program.
How is the perimeter of a square calculated in the program?
By multiplying 4 by the length of one side.
What does the format specifier %.xf indicate in printf()?
It formats the floating point number with x decimal places.
What is the output of 'perimeter' when 'side' is 3?
What is the purpose of the 'main' function in a C program?
It serves as the entry point for program execution.
What assumption can be made about input values in this course?
Input values are always valid unless otherwise stated.
What is the output format used in the printf statements?
It uses the format specifier '%d' for integers.
Is printf a valid identifier?
Yes, it is a valid identifier.
Is 32bits a valid identifier?
No, it is not a valid identifier because it starts with a digit.
如何從用戶讀取數字?
使用 scanf() 函數。
What is the purpose of the printf() function?
To output a piece of text to the screen.
Can you give examples of predefined identifiers in C?
main, printf, scanf.
What escaped sequence is used for a newline in a string constant?
\n.
How do compilers treat whitespace characters during syntax checking?
Compilers usually consider whitespace characters (space, newline, tab) flexibly.
What is the purpose of the #include <stdio.h> directive in a C program?
It includes the standard input-output library for using functions like printf.
What must an identifier not be?
It cannot be one of the reserved words.
What is indentation in programming?
Spacing in front of code lines to improve readability.
What must the user do to resume the program after scanf()?
Enter a value followed by pressing the 'Enter' key.
What is the output of printf() with the format specifier %.7f for the value of pi?
3.1415927
What data type is used for the variable 'side' in the program?
int (integer).
What format specifier is used to read an integer in scanf?
%d
What does the program output when the user inputs '123' and '456.125'?
r1 = 123.000000, r2 = 456.125000.
How is the perimeter of a square calculated in the provided code?
Perimeter is calculated as 4 times the length of a side.
What is the significance of the reserved word 'volatile'?
It indicates that a variable may be changed unexpectedly.
What two characteristics define a variable?
A name and a type.
What is the purpose of the format string in printf?
It specifies the text to print and how to format the output.
如何在程式中使用變數?
通過宣告變數並將值賦給它,然後在程式中引用該變數。
What type of numbers have we been using so far in the examples?
Integers (type int).
What does the escaped sequence \t represent?
A tab character.
What is an example of a valid string constant in C?
"Hello World!"
Why is the '&' operator used before the variable in scanf()?
It is necessary to provide the address of the variable where the input will be stored.
How do line comments in C work?
They begin with // and extend to the end of the line.
What does a decimal point signify in numbers?
It makes a big difference in the type of number.
What is the formula used to calculate the area of the square?
Area is calculated as side * side.
Where are the input values stored when using scanf() with '%d%d'?
The first input value is stored in num1 and the second in num2.
What reserved word is used for conditional statements in C?
if, else, switch.
What happens when scanf() is waiting for user input?
Execution is paused until the user enters the second value and presses 'Enter'.
What is incorrect about the printf() usage: printf("%f ", 10);?
10 is a value of type int, but %f expects a float.
What is incorrect about the printf() usage: printf("%.2d ", 10);?
.2 does not apply to integers.
Is int a valid identifier?
No, it is a reserved word.
Is Notell a valid identifier?
Yes, it is a valid identifier.
Is v a valid identifier?
Yes, it is a valid identifier.
如何格式化輸出的數字?
使用 printf() 函數中的格式說明符。
Why should you avoid using predefined identifiers in your program?
To prevent conflicts with standard library functions and maintain code clarity.
What does the C language's case sensitivity imply?
Identifiers must be used with the correct case; 'Printf' and 'printf' are different.
What is one way to maintain consistency in naming variables?
Use underscores (e.g., interest_rate) or camel case (e.g., interestRate).
What is the escaped sequence for a backslash?
\.
What should you do when a syntax error is found during compilation?
Read the error message carefully for hints to fix your code.
What is the purpose of the main function in a C program?
It serves as the entry point for program execution.
What data type is used to declare 'num1' in the program?
int
What are reserved words in C language?
Names that have special meaning in the C language.
Give an example of a reserved word in C.
auto, break, char, etc.
What is the purpose of the 'main' function in a C program?
It serves as the entry point for program execution.
What is the value assigned to side in the program?
The value assigned to side is 3.
How is the perimeter of the square calculated in the code?
By multiplying the side length by 4.
What is the purpose of the 'main' function in a C program?
It serves as the entry point for program execution.
Is A100xC200 a valid identifier?
Yes, it is a valid identifier.
What does the string constant '\ is " backslash " and / is " slash"' represent when output on screen?
\ is " backslash " and / is " slash"
What does the format string '%d' in scanf() indicate?
It tells scanf() to read one integer.
What are some examples of integers?
0, -100, 2048, 203139, 1000000.
What are the rules that programmers must obey in C?
Syntax.
How do block comments in C work?
They start with /* and end at the next */ and can span multiple lines.
What are some examples of floating point numbers?
0.0, -10.2, 3.1416, .244.
What does the format specifier %.2f do in printf()?
It formats the floating point number to 2 decimal places.
How is the perimeter of the square calculated in the program?
By multiplying 4 by the value of side.
What is the output of printf() with the format specifier %.2f for the value of pi?
3.14
What does the 'printf' function do in the program?
It outputs formatted text to the console.
Which reserved word is used for looping in C?
for, while, do.
What does the printf function do in this program?
It outputs the values of side, perimeter, and area to the console.
Is _ a valid identifier?
Yes, it is a valid identifier.
What are the key concepts for naming variables?
Follow specific rules and conventions to ensure clarity and avoid conflicts.
什麼是變數?
變數是用來儲存數據的命名空間,可以在程式中使用。
What types of names should be avoided in naming conventions?
Names like a, b, c, d, a1, a2, a3, xyz.
What is the purpose of the 'main' function in a C program?
It serves as the entry point for program execution.
What happens to the input value read by scanf()?
It is stored in the variable num1.
What is the purpose of proper spacing in C programming?
It makes the program easier to read.
What is the purpose of the 'main' function in a C program?
It serves as the entry point of the program.
What is the formula used to calculate the area of a square in the program?
side * side.
What does the printf function do in the program?
It outputs formatted text to the console.
What are the values printed for side, perimeter, and area in the example?
Side: 3, Perimeter: 12, Area: 9.
What does the statement 'side = 3;' do?
It assigns the value 3 to the variable 'side'.
What is the output format specifier used to display 'num1'?
%d
What is the value assigned to 'side' in the program?
What does the 'printf' function do in this program?
It outputs formatted text to the console.
What is the significance of the statement 'return 0;' in the program?
It indicates that the program has executed successfully.
What is incorrect about the printf() usage: printf("%d ", 10.0);?
10.0 is a value of type double, but %d expects an integer.
How does the program read user input?
Using scanf() function.
What is the return value of the main function in this program?
0
Is engg1110 a valid identifier?
Yes, it is a valid identifier.
Is c a valid identifier?
Yes, it is a valid identifier.
What type of numbers do we use if we need decimal places?
Floating point numbers (type double).
How is the perimeter of a square calculated in the program?
By multiplying 4 by the length of one side.
What does the printf function do in a C program?
It outputs text to the console.
How are statements executed in a C program?
Sequentially, one after the other.
What does the return 0; statement signify in a C program?
It indicates that the program has completed successfully.
How many decimal places does printf() print by default for floating point numbers?
6 decimal places.
What does the 'printf' function do in this C program?
It outputs formatted text to the console.
What is the formula used to calculate the area of the square in the program?
side * side.
What does the reserved word 'return' do in C?
It exits a function and optionally returns a value.
What is the data type of the variables 'side', 'perimeter', and 'area'?
All are of type 'int'.
What function is used to display a message to the user?
printf()
What does the program output after reading two integers?
num1 and num2 values.
Is URL a valid identifier?
Yes, it is a valid identifier.
Is Int a valid identifier?
Yes, it is a valid identifier (case-sensitive).
Is ~ a valid identifier?
No, it is not a valid identifier.
What data type are the variables r1 and r2 in the program?
double.
What format specifier is used in scanf() for double-typed values?
%lf.
What format specifier is used in printf() for double-typed values?
%f.
What is the significance of the curly braces {} in a C program?
They define the start and end of a block of code.
What is the purpose of reserved words?
They are used to perform specific functions in the C language.
What is the final value of perimeter after the calculation?
The final value of perimeter is 12.
What is the output of 'area' when 'side' is 3?
How is the area of the square calculated in the code?
Area is calculated as side multiplied by itself (side * side).
How are the statements executed in the program?
Sequentially, one by one.
What is incorrect about the printf() usage: printf("% d % d ", 10);?
One argument is omitted.
Is Domain-name a valid identifier?
No, it is not a valid identifier due to the hyphen.
Is main a valid identifier?
Yes, it is a valid identifier.
Is include a valid identifier?
No, it is a reserved word.
Is cost a valid identifier?
Yes, it is a valid identifier.
What does the printf function do in this program?
It outputs the values of side, perimeter, and area to the console.
Name a reserved word that indicates a data type in C.
int, float, double, etc.
What is the final value of area after the calculation?
The final value of area is 9.
What does the program output when executed?
It outputs the side, perimeter, and area of the square.
What library is included at the beginning of the C program?
<stdio.h>
What data types are used for 'num1' and 'num2' in the program?
int (integer).
Is 1_abc_1 a valid identifier?
Yes, it is a valid identifier.
Is _ 27 a valid identifier?
No, it is not a valid identifier due to the space.
Is www_yahoo_com a valid identifier?
Yes, it is a valid identifier.
What does 'return 0;' signify in the main function?
It indicates that the program has executed successfully.
Is engg_1110 a valid identifier?
Yes, it is a valid identifier.
Is VARIABLE a valid identifier?
Yes, it is a valid identifier.
Is Hong Kong a valid identifier?
No, it is not a valid identifier due to the space.
What is the first topic covered in the outline?
First C program & Language Syntax.
What is covered in the fourth point of the outline?
Data Types, Numeric Constants, String Literals.
What does the outline mention after Variables and Assignment Operators?
Identifiers, Reserved Words, Predefined Identifiers.
What is the final topic mentioned in the outline?
Console Input/Output Using scanf() and printf().