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