
CLA-11-03実際の問題解答PDFには100%カバー率リアル試験問題
CLA-11-03試験問題解答
質問 # 12
What happens if you try to compile and run this program?
#include <stdio.h>
int i = 0;
int main (int argc, char *argv[]) {
for(i; 1; i++);
printf("%d", i);
return 0;
}
Choose the right answer:
- A. The program outputs 2
- B. The program outputs 0
- C. The program executes an infinite loop
- D. The program outputs 1
- E. Compilation fails
正解:C
解説:
The for loop in the program is initialized with i (which is 0), has the condition 1 (which is always true), and increments i in each iteration. Since the loop con-dition is always true, the loop will continue indefinitely, and i will keep incre-menting. The program will not reach the printf statement, and it will be stuck in an infinite loop.
*The program defines a global variable i and assigns it the value 0.
*The program defines a main function that takes two parameters: argc and argv.
*The program uses a for loop to increment the value of i as long as the condi-tion 1 is true, which is always the case.
*The program never exits the for loop, so it never reaches the printf function or the return statement.
*The program keeps running indefinitely, consuming CPU resources and memory. This is an example of a logical error in the program.
質問 # 13
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int i = 1, j = 0;
int 1 = !i + !! j;
printf("%d", 1);
return 0;
}
Choose the right answer:
- A. The program outputs 2
- B. The program outputs 0
- C. The program outputs 3
- D. Compilation fails
- E. The program outputs 1
正解:D
解説:
The compilation fails because the program contains a syntax error. The identifier 1 is not a valid name for a variable, as it starts with a digit. Variable names in C must start with a letter or an under-score, and can contain letters, digits, or underscores. The compiler will report an error message such as error: expected identifier or '(' before numeric constant.
References = CLA - C Certified Associate Programmer Certification, C Essentials 1 - (Basics), C Varia-bles
質問 # 14
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int i =2, j = 1;
if(i / j)
j += j;
else
i += i;
printf("%d",i + j);
return 0;
}
Choose the right answer:
- A. The program outputs 4
- B. The program outputs 3
- C. The program outputs 1
- D. Compilation fails
- E. The program outputs 5
正解:A
解説:
In the if statement, i / j is 2 / 1, which is true. Therefore, the if block is executed, and j += j; doubles the value of j (j becomes 2).
After the if-else statement, printf("%d", i + j); prints the sum of i and the updated val-ue of j (2 + 2), which is
4.
質問 # 15
What happens if you try to compile and run this program?
#include <stdio.h>
int main(int argc, char *argv[]) {
int i = 10 - 2 / 5 * 10 / 2 - 1;
printf("%d",i);
return 0;
}
Choose the right answer:
- A. The program outputs 4
- B. The program outputs 0
- C. The program outputs 15
- D. The program outputs 9
- E. Compilation fails
正解:D
解説:
The expression 10 - 2 / 5 * 10 / 2 - 1 is evaluated based on the standard precedence rules in C. Division and multiplication have higher precedence than addition and subtrac-tion, and they are evaluated from left to right:
1.2 / 5 evaluates to 0 (integer division).
2.0 * 10 evaluates to 0.
3.0 / 2 evaluates to 0.
4.10 - 0 - 1 evaluates to 9.
Therefore, the correct answer is "The program outputs 9."
質問 # 16
What is the meaning of the following declaration?
float ** p;
Choose the right answer:
- A. p is a pointer to a pointer to a float
- B. p is a float pointer to a float
- C. The declaration is erroneous
- D. p is a pointer to a float
- E. p is a pointer to a float pointer
正解:A
解説:
The declaration float **p; means that p is a pointer to a pointer to a float. It is used to declare a pointer that can point to another pointer, and that pointer, in turn, can point to a float.
質問 # 17
-
What happens if you try to compile and run this program?
#include <stdio.h>
int *f();
int main (int argc, char *argv[]) {
int *p;
p = f();
printf("%d",*p);
return 0;
}
int *f() {
static v = 1;
return &v;
}
Choose the right answer:
- A. The program outputs 2
- B. The program outputs 0
- C. The program outputs 3
- D. The program outputs 1
- E. Compilation fails
正解:D
解説:
The program outputs 1 because the static variable v is initialized to 1 inside the f function, and it is visible to the main function. The f function returns the address of v, which is a pointer to an int. The main function dereferences the pointer and assigns it to p, which is another pointer to an int. Then, the main function prints the value of *p, which is the same as dereferencing p again. Therefore, the output of the program is:
f() = &v p = f() printf("%d",*p) = &v = 1
The other options are incorrect because they either do not match the output of the program or do not use the correct concept of static variables.
質問 # 18
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
char *p = "World";
int i = 2;
switch (p[i]) {
case 'W' :i++; break ;
case 'o' :i += 2; break ;
case 'r' :i += 3; break ;
case '1' :i += 4; break ;
case 'd' :i += 5; break ;
default :i += 4;
}
printf("%d", i);
return 0;
}
-
Choose the right answer:
- A. The program outputs 4
- B. The program outputs 5
- C. The program outputs 3
- D. Compilation fails
- E. The program outputs 6
正解:B
解説:
*The program defines a pointer p that points to the string literal "World".
*The program also defines an integer variable i and assigns it the value 2.
*The program uses a switch statement to check the value of p[i], which is the third character of the string
"World", i.e. 'r'.
*The program finds a matching case for 'r' and executes the statement i += 3;, which adds 3 to the value of i.
Then it breaks out of the switch statement.
*The program prints the value of i, which is now 5, using the printf function.
*The program returns 0 and exits.
質問 # 19
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
char *t = "abcdefgh";
char *p = t + 2;
int i;
p++;
p++;
printf("%d ", p[2] - p[-1]);
return 0;
}
Choose the right answer:
- A. The program outputs 2
- B. The program outputs 4
- C. The program outputs 3
- D. Execution fails
- E. Compilation fails
正解:C
解説:
The program outputs 3 because the expression p[2] - p[-1] evaluates to 3 using the pointer arithmetic rules in C: The pointer t points to the first element of the string literal "abcdefgh", which is stored in a read-only memory location. The pointer p is initialized to t + 2, which means it points to the third element of the string, which is 'c'. Then, p is incremented twice, so it points to the fifth ele-ment of the string, which is 'e'. The subscript operator [] is equivalent to adding an offset to the pointer and dereferencing it, so p[2] is the same as
*(p + 2), which is 'g', and p[-1] is the same as *(p - 1), which is 'd'. The printf function then prints the difference between the ASCII values of 'g' and 'd', which is 103 - 100 = 3, as a decimal integer using the %d format specifier.
References = CLA - C Certified Associate Programmer Certification, C Essentials 2 - (Intermediate), C Pointers, C Strings
質問 # 20
What happens if you try to compile and run this program?
#include <stdio.h>
int main(int argc, char *argv[]) {
int i = 2 / 1 + 4 / 2;
printf("%d",i);
return 0;
}
Choose the right answer:
- A. The program outputs 4
- B. The program outputs 0
- C. The program outputs 3
- D. Compilation fails
- E. The program outputs 5
正解:A
解説:
The program outputs 4 because the expression 2 / 1 + 4 / 2 evaluates to 4 using the integer arithmetic rules in C: The division operator / performs integer division when both operands are inte-gers, which means it discards the fractional part of the result. Therefore, 2 / 1 is 2 and 4 / 2 is 2, and their sum is 4. The printf function then prints the value of i as a decimal integer using the %d format specifier.
References = CLA - C Certified Associate Programmer Certification, C Essentials 2 - (Intermediate), C Operators
質問 # 21
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int main, Main, mAIN = 1;
Main = main = mAIN += 1;
printf ("%d", MaIn) ;
return 0;
}
Choose the right answer:
- A. The program outputs 2
- B. The program outputs an unpredictable value
- C. The program outputs 3
- D. Compilation fails
- E. The program outputs 1
正解:D
解説:
The program is not a valid C program and cannot be compiled successfully. The reason is that the program uses the same name main for both a function and a variable, which is not allowed in C. The name main is a reserved keyword that denotes the entry point of the program, and it cannot be redefined or reused for any other purpose. Therefore, the compiler will report an error and the program will not run. References = C - main() function - Tutorialspoint, C Keywords - GeeksforGeeks, C Basic Syntax
質問 # 22
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int i = 7 || 0 ;
printf("%d", !! i);
return 0;
}
Choose the right answer:
- A. The program outputs 0
- B. The program outputs 1
- C. The program outputs -1
- D. The program outputs 7
- E. Compilation fails
正解:B
解説:
The program is a valid C program that can be compiled and run without errors. The program uses the || operator to perform a logical OR operation on the values of 7 and 0, which are both integer literals. The logical OR operator returns 1 if either operand is non-zero, and 0 otherwise. The program assigns the result of this operation to the variable i, which is an integer. The program then prints the value of !!i using the printf function. The !! operator is a double negation, which converts any non-zero value to 1, and 0 to 0. Since i is 1,
!!i is also 1. Therefore, the program outputs 1.
質問 # 23
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
char *p = "John" " " "Bean";
printf("[%s]", p) ;
return 0;
}
Choose the right answer:
- A. The program outputs [John Bean]
- B. The program outputs nothing
- C. The program outputs two lines of text
- D. The program outputs "[]"
- E. The program outputs three lines of text
正解:A
解説:
The string literal "John" " " "Bean" is effectively concatenated into a single string by the compiler during compilation. Therefore, the value of p becomes a pointer to the string "John Bean". The printf statement then prints the string enclosed within square brackets, resulting in the output [John Bean].
質問 # 24
What happens when you compile and run the following program?
#include <stdio.h>
#define SYM
#define BOL 100
#undef SYM
int main (void) {
#ifdef SYM
int i = 100;
#else
int i= 200;
#endif
int j = i + 200;
printf("%d",i+j);
return 0;
}
Select the correct answer:
- A. The program outputs 600
- B. The program outputs 300
- C. The program outputs 100
- D. The program outputs 400
- E. The program outputs 200
正解:A
解説:
The program outputs 600 because the #ifdef directive checks if the macro SYM is defined, and if so, executes the code between it and the corresponding #else or #endif directive. Otherwise, it skips that code and executes the code after the #else directive, if any. In this program, the macro SYM is defined by the #define directive, but then undefined by the #undef directive, which removes the def-inition of a macro. Therefore, the code between the #ifdef and the #else directives is skipped, and the code after the #else directive is executed, which assigns 200 to the variable i. The variable j is then assigned the sum of i and 200, which is 400. The printf function then prints the sum of i and j, which is 600, as a decimal integer using the %d format specifier.
References = CLA - C Certified Associate Programmer Certification, C Essentials 2 - (Intermediate), C Preprocessor
質問 # 25
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
float f = 1e1 + 2e0 + 3e-1;
printf("%f ",f);
return 0;
}
Choose the right answer:
- A. The program outputs 12300.000
- B. The program outputs 12.300000
- C. The program outputs 123.00000
- D. Compilation fails
- E. The program outputs 1230.0000
正解:B
解説:
The program outputs 12.300000 because the printf function prints the value of f with a precision of 6 decimal places, which is the default precision for floating-point literals in C. The %f format specifier indicates that the argument is a floating-point value, and the space before it indicates that there should be a decimal point. The argument f is a float literal that represents 1e1 + 2e0 + 3e-1, which is equivalent to 1000000000 + 20000000 +
0.003 in decimal notation. Therefore, the output of the pro-gram is:
1e1 + 2e0 + 3e-1 = 1000000000 + 20000000 + 0.003 = 1230000000.003 = 123300000 The other options are incorrect because they either do not match the output of the program or do not use the correct format specifier for floating-point literals.
質問 # 26
What happens if you try to compile and run this program?
#include <stdio.h>
#include <stdlib.h>
void fun (void) {
return 3.1415;
}
int main (int argc, char *argv[]) {
int i = fun(3.1415);
printf("%d",i);
return 0;
}
Choose the right answer:
- A. The program outputs 4
- B. The program outputs 3
- C. The program outputs 3.1415
- D. Execution fails
- E. Compilation fails
正解:E
解説:
The program is not a valid C program and cannot be compiled successfully. The reason is that the program has two syntax errors:
*The function fun has a void return type, which means it cannot return any value. However, the function tries to return a floating-point value of 3.1415, which is incompatible with the re-turn type. This will cause a compilation error.
*The function main is defined inside the function fun, which is not allowed in C. A function cannot be nested inside another function. This will also cause a compilation error.
To fix these errors, the function fun should have a double return type, and the function main should be defined outside the function fun. For example:
#include <stdio.h>
#include <stdlib.h>
double fun (void) { return 3.1415; }
int main (int argc, char *argv[]) { int i = fun(3.1415); printf("%d",i); return 0; } References = C - Functions - Tutorialspoint, C - return Statement - Tutorialspoint, C Basic Syntax
質問 # 27
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
char i = 20 + 020 + 0x20;
printf("%d",i);
return 0;
}
Choose the right answer:
- A. The program outputs 86
- B. The program outputs 60
- C. The program outputs 62
- D. Compilation fails
- E. The program outputs 68
正解:E
解説:
*The program is a valid C program that can be compiled and run without errors.
*The variable i is declared as a char, which is an 8-bit signed integer type that can store val-ues from -128 to
127.
*The expression 20 + 020 + 0x20 evaluates to 68, because:
o20 is a decimal literal with the value 20
o020 is an octal literal with the value 16 (8^1 * 2 + 8^0 * 0)
o0x20 is a hexadecimal literal with the value 32 (16^1 * 2 + 16^0 * 0)
oThe + operator performs arithmetic addition on the operands and returns the sum
*The printf function prints the value of i as a decimal integer using the %d format specifier.
*The output of the program is 68.
質問 # 28
......
CLA-11-03試験練習テスト問題:https://www.jpntest.com/shiken/CLA-11-03-mondaishu
合格させるCLA-11-03試験情報と無料練習テスト:https://drive.google.com/open?id=17L1Y3BXszKzwx5_f2J2jJJViCKrfek0C