2024年04月最新のC++ Institute CLA-11-03問題集で更新された41問あります [Q19-Q38]

Share

2024年04月最新のC++ Institute CLA-11-03問題集で更新された41問あります

PDF無料ダウンロードにはCLA-11-03有効な練習テスト問題

質問 # 19
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. Compilation fails
  • B. The program outputs 0
  • C. The program outputs 3
  • D. The program outputs 5
  • E. The program outputs 4

正解:E

解説:
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


質問 # 20
Assume that ints and floats are 32-bit wide.
What happens if you try to compile and run this program?
#include <stdio.h>
union uni {
float f, g;
int i, j;
};
int main (int argc, char *argv[]) {
union uni u;
printf ("%ld", sizeof (u) ) ;
return 0;
}
Choose the right answer:

  • A. Compilation fails
  • B. The program outputs 16
  • C. The program outputs 8
  • D. The program outputs 24
  • E. The program outputs 4

正解:E

解説:
This is because when you initialize u with some values, only one member of u will be as-signed a value at a time, and the rest will remain uninitialized. Therefore, when you print sizeof(u), it will show the size of the largest member, which is f in this case. Since f is 4 bytes long, sizeof(u) will be 4 bytes as well.
If you want to learn more about unions in C programming, you can check out these re-sources:
*C Unions - GeeksforGeeks
*C Unions (With Examples) - Programiz
*C - Unions - Online Tutorials Library


質問 # 21
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int i = 20;
printf("%x", i);
return 0;
}
-
Choose the right answer:

  • A. Compilation fails
  • B. The program outputs 14
  • C. The program outputs 20
  • D. The program outputs 10
  • E. The program outputs 24

正解:B

解説:
The program outputs 14 because the printf function prints the value of i as a hexadecimal integer using the %x format specifier. The hexadecimal system uses 16 symbols to represent numbers, from 0 to 9 and from A to F.
Each symbol corresponds to a decimal value, for example, A is 10, B is 11, C is 12, and so on. To convert a decimal number to a hexadecimal number, we need to divide the number by 16 repeatedly and write down the remainder in reverse order. For example, to convert 20 to hexa-decimal, we do:
20 / 16 = 1, remainder 4 1 / 16 = 0, remainder 1
The hexadecimal number is 14, as we write the remainders from right to left.
References = CLA - C Certified Associate Programmer Certification, C Essentials 2 - (Intermediate), C printf and scanf functions, Hexadecimal number system


質問 # 22
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
char *s = "\\\"\\\\";
printf ("[%c]", s [1]);
return 0;
}
Choose the right answer:

  • A. Compilation fails
  • B. Execution fails
  • C. The program outputs []
  • D. The program outputs []
  • E. The program outputs ["]

正解:B

解説:
In the program, the character array char *s = "\\\"\\\\"; is defined with the value "\"\\". When printing s[1] using printf("[%c]", s[1]);, it prints the character at index 1 of the string.
Here's the breakdown of the string \\\"\\\\:
*s[0] is '\'
*s[1] is '"'
So, the program outputs ["]. Therefore, the correct answer is B. The program outputs ["]


質問 # 23
What happens if you try to compile and run this program?
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
double x = 1234567890.0;
printf ("%f",x);
return 0;
}
Choose the most precise answer:

  • A. Compilation fails
  • B. The program outputs a value greater than 1234500000.0 and less than 1234600000.0
  • C. Execution fails
  • D. The program outputs 1234567890.0
  • E. The program outputs 1234567900.0

正解:D

解説:
To understand the behavior of this program, let's first analyze its structure:
1.It includes the standard I/O library, <stdio.h>, and the standard library, <stdlib.h>, although <stdlib.h> is not used in this program.
2.main function declares a double variable x initialized to 1234567890.0.
3.It then prints x using %f format specifier in printf.
Key Points to Consider:
*The double data type in C is typically capable of representing a wide range of deci-mal numbers quite accurately.
*The %f format specifier in printf is used for outputting a float or double as a fixed-point number.
*There may be some precision issues when dealing with floating-point numbers, but these generally occur with more complex calculations or when the numbers are ex-tremely large or small.
Given that 1234567890.0 is a straightforward decimal number well within the representable range of a double, and the program doesn't perform any complex calculations, we can ex-pect the output to be quite close to the actual value of x.
However, due to the way floating-point numbers are represented and handled in C, there can be slight discrepancies in the least significant digits due to rounding or representation errors.


質問 # 24
Assume that we can open a file called "file1".
What happens when you try to compile and run the following program?
#include <stdio.h>
int main (void) {
FILE *f;
int i;
f = fopen("file1","wb");
fputs("545454",f);
fclose (f);
f = fopen("file1","rt");
fscanf(f,"%d ", &i);
fclose (f) ;
printf("%d",i);
return 0;
}
Choose the right answer:

  • A. Compilation fails
  • B. Execution fails
  • C. The program outputs 0
  • D. The program outputs 545454
  • E. The program outputs 54

正解:D

解説:
The program outputs 545454 because the fputs function writes the string "545454" to the file "file1" in binary mode, and the fscanf function reads the string as an integer from the file in text mode. The binary mode and the text mode are different ways of interpreting the data in a file. In binary mode, the data is stored as a sequence of bytes, and no translation is performed. In text mode, the data is stored as a sequence of characters, and some characters may be translated depending on the plat-form. For example, the newline character may be translated to a carriage return and a line feed on Windows, or just a line feed on Linux. The fopen function takes a mode argument that specifies whether the file should be opened in binary or text mode. The mode
"wb" means write binary, and the mode "rt" means read text.
When the fputs function writes the string "545454" to the file in binary mode, it writes the ASCII val-ues of each character as a byte. The ASCII value of '5' is 53, and the ASCII value of '4' is 52. There-fore, the file contains the following bytes: 53 53 53 52 52 52. When the fscanf function reads the file in text mode, it interprets the bytes as characters and converts them to an integer using the %d format specifier. The %d format specifier expects a decimal integer, which is a number com-posed of digits from 0 to 9. Since the file contains only digits, the fscanf function successfully con-verts the string "545454" to an integer with the same value.
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 File I/O, ASCII Table


質問 # 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. Compilation fails
  • B. The program outputs 123.00000
  • C. The program outputs 1230.0000
  • D. The program outputs 12.300000
  • E. The program outputs 12300.000

正解:D

解説:
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 when you compile and run the following program?
#include <stdio.h>
int fun (void) {
static int i = 1;
i += 2;
return i;
}
int main (void) {
int k, 1;
k = fun ();
1 = fun () ;
printf ("%d", 1 - k);
return 0;
}
Choose the right answer:

  • A. The program outputs 0
  • B. The program outputs 3
  • C. The program outputs 1
  • D. The program outputs 4
  • E. The program outputs 2

正解:E

解説:
The provided program has a few key points to consider:
1.fun is a function that uses a static variable i. This means i retains its value between function calls. It's initialized to 1 and then incremented by 2 each time fun is called.
2.The main function calls fun twice, assigning the results to k and l (though there's a typo in the variable name l, it should be l = fun();, not 1 = fun();).
Let's step through the code:
*First call to fun: i starts at 1, increments by 2, so i becomes 3. This value (3) is as-signed to k.
*Second call to fun: i is now 3, increments by 2 again, so i becomes 5. This value (5) is assigned to l.
Finally, the printf statement attempts to print l - k, which is 5 - 3, resulting in 2.
So, the correct answer is:
A: The program outputs 2.


質問 # 27
What happens if you try to compile and run this program?
#include <stdio.h>
int main (int argc, char *argv[]) {
int i = 1;
for(;i > 128;i *= 2);
printf("%d", i) ;
return 0;
}
-
Choose the right answer:

  • A. Compilation fails
  • B. The program outputs 128
  • C. The program outputs a value less than 128
  • D. The program outputs a value greater than 128
  • E. The program enters an infinite loop

正解:C

解説:
The main function declares an integer i and initializes it to 1. Then, it enters a for loop with no initialization statement, a condition i > 128, and an iteration expression i *= 2. The loop will continue to execute as long as i is greater than 128, but since i starts at 1, the loop's condition is false right from the start, meaning the loop body never executes.
However, this looks like an oversight, because usually, with this kind of loop, the intention is to run the loop until the condition becomes false. If the condition were i < 128, i would double each iteration until it reached or exceeded 128.
Given the current condition i > 128, the loop does nothing, and printf will output the ini-tial value of i, which is 1.


質問 # 28
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 three lines of text
  • B. The program outputs "[]"
  • C. The program outputs [John Bean]
  • D. The program outputs two lines of text
  • E. The program outputs nothing

正解:C

解説:
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].


質問 # 29
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. Compilation fails
  • B. The program outputs 0
  • C. The program outputs 1
  • D. The program outputs 7
  • E. The program outputs -1

正解:C

解説:
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.


質問 # 30
What happens if you try to compile and run this program?
#include <stdio.h>
fun (void) {
static int n = 3;
return --n;
}
int main (int argc, char ** argv) {
printf("%d \n", fun() + fun());
return 0;
}
Select the correct answer:

  • A. The program outputs 3
  • B. The program outputs 0
  • C. The program outputs 1
  • D. The program outputs 4
  • E. The program outputs 2

正解:A

解説:
The program outputs 3 because the fun function returns the value of --n, which is a post-increment operator.
This means that the value of n is decremented by 1 before it is returned. Therefore, fun() returns 3, which is the original value of n before decrementing. The main function calls fun() twice and adds the results, which gives 3 + 3 = 6. Then, the main function prints the result with a %d format specifier, which shows the integer part of the result. Therefore, the output of the program is:
fun() = 3 fun() = 3 printf("%d \n", fun() + fun()) = 6 = 3


質問 # 31
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. Compilation fails
  • B. The program outputs 3
  • C. The program outputs 5
  • D. The program outputs 6
  • E. The program outputs 4

正解:C

解説:
*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.


質問 # 32
What happens if you try to compile and run this program?
#include <stdio.h>
int fun(int i) {
return i++;
}
int main (void) {
int i = 1;
i = fun(i);
printf("%d",i);
return 0;
}
Choose the correct answer:

  • A. Compilation fails
  • B. The program outputs 0
  • C. The program outputs 1
  • D. The program outputs an unpredictable value
  • E. The program outputs 2

正解:C

解説:
In the fun function:
cCopy code
int fun(int i) { return i++; }
The post-increment operator i++ returns the current value of i and then increments it. So, fun(i) will return the current value of i (which is 1) and then increment i to 2.
In the main function:
cCopy code
int i = 1; i = fun(i); printf("%d", i);
Here, i is assigned the result of fun(i), which is 1. So, the program prints the value of i, which is 1.
Therefore, the correct answer is D. The program outputs 1.


質問 # 33
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 three lines of text
  • B. The program outputs "[]"
  • C. The program outputs [John Bean]
  • D. The program outputs two lines of text
  • E. The program outputs nothing

正解:C


質問 # 34
What happens if you try to compile and run this program?
#include <stdio.h>
#include <string.h>
int main (int argc, char *argv[]) {
int a = 0, b = 1, c;
c = a++ && b++;
printf("%d",b);
return 0;
}
Choose the right answer:

  • A. Compilation fails
  • B. The program outputs 0
  • C. The program outputs 1
  • D. The program outputs 3
  • E. The program outputs 2

正解:C

解説:
he expression a++ && b++ involves the logical AND (&&) operator. In C, the logical AND op-erator short-circuits, meaning that if the left operand (a++ in this case) is false, the right operand (b++) is not evaluated.
Initially, a is 0, and b is 1. The result of a++ is 0 (false), so b++ is not evaluated. The value of b remains 1. The printf statement then prints the value of b, which is 1.
Therefore, the correct answer is "The program outputs 1."
References = CLA - C Associate Programmer documents


質問 # 35
......

CLA-11-03テストエンジンお試しセット、CLA-11-03問題集PDF:https://www.jpntest.com/shiken/CLA-11-03-mondaishu

最新のC++ Institute CLA-11-03のPDFと問題集で(2024)無料試験問題解答はここ:https://drive.google.com/open?id=13iRvRVajCn_FnANMnVZbA7-ljHQ9YI4c

弊社を連絡する

我々は12時間以内ですべてのお問い合わせを答えます。

オンラインサポート時間:( UTC+9 ) 9:00-24:00
月曜日から土曜日まで

サポート:現在連絡