Text Material Preview
<p>CLA-11-03</p><p>Exam Name: CLA - C Certified Associate Programmer</p><p>Full version: 40 Q&As</p><p>Full version of CLA-11-03 Dumps</p><p>Share some CLA-11-03 exam dumps below.</p><p>1. Assume that ints are 32-bit wide.</p><p>What happens if you try to compile and run this program?</p><p>#include <stdio.h></p><p>typedef union {</p><p>int i;</p><p>1 / 8</p><p>https://www.certqueen.com/CLA-11-03.html</p><p>int j;</p><p>int k;</p><p>} uni;</p><p>int main (int argc, char *argv[]) {</p><p>uni s;</p><p>s.i = 3;</p><p>s.j = 2;</p><p>s.k = 1;</p><p>printf("%d",s.k * (s.i - s.j));</p><p>return 0;</p><p>}</p><p>Choose the right answer:</p><p>A. The program outputs 9</p><p>B. The program outputs 0</p><p>C. Execution fails</p><p>D. Compilation fails</p><p>E. The program outputs 3</p><p>Answer: B</p><p>Explanation</p><p>The program defines a union named uni with three members: i, j, and k. The members share the</p><p>same memory location. The values are assigned to s.i, s.j, and s.k, but since they share the</p><p>same memory, the value of s.i will overwrite the values of s.j and s.k.</p><p>So, s.i will be 3, and both s.j and s.k will be 3. Then, the expression s.k * (s.i - s.j) be-comes 3 *</p><p>(3 - 3), which equals 0. The printf statement prints the result, and the pro-gram outputs 0.</p><p>The program is a valid C program that can be compiled and run without errors. The program</p><p>defines a union type named uni that contains three int members: i, j, and k. Then it creates a</p><p>variable of type uni named s and assigns values to its members. However, since a union can</p><p>only hold one member value at a time, the last assignment (s.k = 1) overwrites the previous</p><p>values of s.i and s.j. Therefore, all the members of s have the same value of 1. The program</p><p>then prints the value of s.k * (s.i - s.j), which is 1 * (1 - 1) = 0. Therefore, the program outputs 0.</p><p>References = C Unions - GeeksforGeeks, C Unions (With Examples) - Programiz, C - Unions -</p><p>Online Tutorials Library</p><p>2. What happens if you try to compile and run this program?</p><p>#include <stdio.h></p><p>struct s {</p><p>2 / 8</p><p>int i;</p><p>};</p><p>void fun(struct S st) {</p><p>st.i --;</p><p>int main (void) {</p><p>int k;</p><p>struct $ str1 = { 2 };</p><p>fun (str1) ;</p><p>k =str1.i; printf("%d", k); return 0;</p><p>}</p><p>-</p><p>Choose the correct answer:</p><p>A. The program outputs 3</p><p>B. Compilation fails</p><p>C. The program outputs 1</p><p>D. The program outputs 2</p><p>E. The program outputs 0</p><p>Answer: D</p><p>Explanation</p><p>The provided C program defines a struct S with one member i, a function fun that takes a struct</p><p>S as an argument and decrements its i member, and a main function that creates a struct S,</p><p>calls fun with it, and then</p><p>prints the value of i from the struct.</p><p>Let's go through the main points of the program:</p><p>3. What happens if you try to compile and run this program?</p><p>#include <stdio.h></p><p>int main (int argc, char *argv[]) {</p><p>char *t = "abcdefgh";</p><p>char *p = t + 2;</p><p>int i;</p><p>p++;</p><p>p++;</p><p>printf("%d ", p[2] - p[-1]);</p><p>C++ Institute - CLA-11-03</p><p>return 0;</p><p>3 / 8</p><p>}</p><p>Choose the right answer:</p><p>A. The program outputs 3</p><p>B. The program outputs 4</p><p>C. Execution fails</p><p>D. The program outputs 2</p><p>E. Compilation fails</p><p>Answer: A</p><p>Explanation</p><p>The program outputs 3 because the expression p[2] - p[-1] evaluates to 3 using the pointer</p><p>arithmetic rules in</p><p>C. The pointer t points to the first element of the string literal "abcdefgh", which is stored in a</p><p>read-only memory location. The pointer p is initialized to t + 2, which means it points to the third</p><p>element of the string, which is 'c'. Then, p is incremented twice, so it points to the fifth ele-ment</p><p>of the string, which is 'e'. The subscript operator [] is equivalent to adding an offset to the pointer</p><p>and dereferencing it, so p[2] is the same as *(p + 2), which is 'g', and p[-1] is the same as *(p -</p><p>1), which is 'd'. The printf function then prints the difference between the ASCII values of 'g' and</p><p>'d', which is 103 - 100 = 3, as a decimal integer using the %d format specifier.</p><p>References = CLA C C Certified Associate Programmer Certification, C Essentials 2 -</p><p>(Intermediate), C Pointers, C Strings</p><p>4. What happens if you try to compile and run this program?</p><p>#include <stdio.h></p><p>int f1(int n) {</p><p>return n = n * n;</p><p>}</p><p>int f2(int n) {</p><p>return n = f1(n) * f1(n);</p><p>}</p><p>int main(int argc, char ** argv) {</p><p>printf ("%d \n", f2(1));</p><p>return 0;</p><p>}</p><p>-</p><p>Select the correct answer:</p><p>A. The program outputs 8</p><p>4 / 8</p><p>B. The program outputs 2</p><p>C. Execution fails</p><p>D. The program outputs 4</p><p>E. The program outputs 1</p><p>Answer: E</p><p>Explanation</p><p>In the f1 function, n = n * n; squares the input n and assigns the result back to n.</p><p>In the f2 function, f1(n) * f1(n) calls f1 twice with the input n and multiplies the results.</p><p>In the main function, printf("%d \n", f2(1)); prints the result of f2(1).</p><p>Let's calculate:</p><p>5. f1(1) returns 1 * 1 = 1.</p><p>6. f2(1) calls f1 twice with the input 1, so it's f1(1) * f1(1) = 1 * 1 * 1 * 1 = 1.</p><p>7. What happens if you try to compile and run this program?</p><p>#include <stdio.h></p><p>int main (int argc, char *argv[]) {</p><p>int i = 1, j = 0;</p><p>int 1 = !i + !! j;</p><p>printf("%d", 1);</p><p>return 0;</p><p>}</p><p>Choose the right answer:</p><p>A. Compilation fails</p><p>B. The program outputs 2</p><p>C. The program outputs 3</p><p>D. The program outputs 1</p><p>E. The program outputs 0</p><p>Answer: A</p><p>Explanation</p><p>The compilation fails because the program contains a syntax error. The identifier 1 is not a valid</p><p>name for a variable, as it starts with a digit. Variable names in C must start with a letter or an</p><p>under-score, and can contain letters, digits, or underscores. The compiler will report an error</p><p>message such as error: expected identifier or '(' before numeric constant.</p><p>References = CLA C C Certified Associate Programmer Certification, C Essentials 1 - (Basics),</p><p>C Varia-bles</p><p>5 / 8</p><p>8. What happens if you try to compile and run this program?</p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p>void fun (void) {</p><p>return 3.1415;</p><p>}</p><p>int main (int argc, char *argv[]) {</p><p>int i = fun(3.1415);</p><p>printf("%d",i);</p><p>return 0;</p><p>}</p><p>Choose the right answer:</p><p>A. The program outputs 3</p><p>B. The program outputs 3.1415</p><p>C. The program outputs 4</p><p>D. Execution fails</p><p>E. Compilation fails</p><p>Answer: E</p><p>Explanation</p><p>The program is not a valid C program and cannot be compiled successfully. The reason is that</p><p>the program has two syntax errors:</p><p>•The function fun has a void return type, which means it cannot return any value. However, the</p><p>function tries to return a floating-point value of 3.1415, which is incompatible with the re-turn</p><p>type. This will cause a compilation error.</p><p>•The function main is defined inside the function fun, which is not allowed in</p><p>C. A function cannot be nested inside another function. This will also cause a compilation error.</p><p>To fix these errors, the function fun should have a double return type, and the function main</p><p>should be defined outside the function fun. For example:</p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p>double fun (void) { return 3.1415; }</p><p>int main (int argc, char *argv[]) { int i = fun(3.1415); printf(“%d”,i); return 0; }</p><p>References = C - Functions - Tutorialspoint, C - return Statement - Tutorialspoint, C Basic</p><p>Syntax</p><p>9. What happens when you compile and run the following program?</p><p>6 / 8</p><p>#include <stdio.h></p><p>int fun(void) {</p><p>static int i = 1;</p><p>i++;</p><p>return i;</p><p>}</p><p>int main (void) {</p><p>int k, l;</p><p>k = fun ();</p><p>l = fun () ;</p><p>printf("%d",l + k);</p><p>return 0;</p><p>}</p><p>Choose the right answer:</p><p>A. The program outputs 5</p><p>B. The program outputs 2</p><p>C. The program outputs 1</p><p>D. The program outputs 4</p><p>E. The program outputs 3</p><p>Answer: A</p><p>Explanation</p><p>The program defines a function fun with a static variable i. The main function declares two</p><p>variables k and 1 (Note: The second variable has an invalid name, it should be changed to a</p><p>valid identifier).</p><p>The fun function is called twice, and each time it increments the static variable i by 1. The</p><p>values assigned to k and 1 become 2 and 3, respectively. The printf statement then prints the</p><p>result of 1 + k, which is 3 + 2 equal to 5.</p><p>Therefore, the correct answer is</p><p>"The program outputs 5."</p><p>10. GAMMA is defined as 1.</p><p>7 / 8</p><p>More Hot Exams are available.</p><p>350-401 ENCOR Exam Dumps</p><p>350-801 CLCOR Exam Dumps</p><p>200-301 CCNA Exam Dumps</p><p>Powered by TCPDF (www.tcpdf.org)</p><p>8 / 8</p><p>https://www.certqueen.com/promotion.asp</p><p>https://www.certqueen.com/350-401.html</p><p>https://www.certqueen.com/350-801.html</p><p>https://www.certqueen.com/200-301.html</p><p>http://www.tcpdf.org</p>