click below
click below
Normal Size Small Size show me how
FA1 CS0053
| Question | Answer |
|---|---|
| What does the following code do? for (int index = 0; index < 5; index++) cin >> numbers[index]; | Place data into a five element array called numbers. |
| What is the index number of the last element of an array with 29 elements? | 28 |
| How many objects are present after the following code fragment has executed? double[] ann = new double[ 7 ]; double[] bob; bob = ann; | 1 |
| What is the output of the following code fragment: int[] z = new int[9]; z[0] = 7; z[1] = 3; z[2] = 4; System.out.println( z[0] + z[1] + " " + z[5] ); | 10 0 |
| What are the valid indexes for the array shown below? int myArray[25]; | 0-24 |
| Which of the following gives the memory address of the first element in array foo, an array with 100 elements? | foo; |
| In the statement a[3] = 5, which of the following is the index value? | 3 |
| When you pass an array into a function as an argument: | the function can modify the contents of the array |
| Which of the following array declarations is invalid? | double array2[20,0]; |
| Which of the following is a two-dimensional array? | int anarray[20][20]; |
| What is the last legal subscript that can be used with the following array? int values[5]; | 4 |
| Which of the following is a valid C++ array definition? | int nums[10]; |
| To indicate that 100 locations should be reserved for the integer array p, the programmer should write the declaration int p[99]; | false |
| A single value in an array is addressed by specifying... | the name of the array followed by the index of the element. |
| A pointer can be assigned to array variable. | false |
| What is the output? #include <stdio.h> int main() { int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12}; printf("%u, %u, %u", (a[0] + 1), *(a[0] + 1), *(*(a + 0) + 1)); return 0; } | address of 2,2,2 |
| using a pointer you are directly accessing the value of a given variable. | false |
| It is a construct that gives you more control of the computer's memory. | pointers |
| What is the output? struct node{ int i; float j; } struct node *s[10]; | An array, each element of which is a pointer to a structure of type node |
| It determined the address of a variable, and you can then assign that address to a pointer variable | & operators |
| Also known as dereference operator | * operator |
| What is the output? #include <stdio.h> int main() { int* ptr; *ptr = 5; printf("%d", *ptr); return 0; } | runtime error |
| To move the pointer p to the next location in an array we use *p+=1; | false |
| Give p1 = p2, changes the value of | p1 |
| Which of the following is the proper keyword to deallocate memory? | free |
| In C++ a dynamic memory structure always used pointer. | true |
| Used to create variables that have no identifiers to serve as their names | new |
| Insufficient available memory will return into | NULL |
| What is the output? #include <stdio.h> int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d %d", *ptr, a); return 0; } | 11 11 |
| The subscript (or index) of an array can be... | an integer |
| Given the following declaration, where is 77 stored in the scores array? int scores[]={83, 62, 77, 97}; | scores[2] |
| An array can store a group of values, but the values must be... | the same data type |
| For which of the following applications is an array NOT suitable: | Holding the name, social security number, age, and income of one individual |
| What is the output of the following code fragment: int[] ar = {2, 4, 6, 8 }; System.out.println( ar[0] + " " + ar[1] ); | 2 4 |
| What is the output of the following code fragment: int[] zip = new int[5]; zip[0] = 7; zip[1] = 3; zip[2] = 4; zip[3] = 1; zip[4] = 9; System.out.println( zip[ 2 + 1 ] ); | 1 |
| What is the output of the following code fragment: int[] zip = new int[5]; zip[0] = 7; zip[1] = 3; zip[2] = 4; zip[3] = 1; zip[4] = 9; int j = 3; System.out.println( zip[ j-1 ] ); | 4 |
| What are the legal indexes for the array ar, given the following declaration: int[] ar = {2, 4, 6, 8 } | 0, 1, 2, 3 |
| Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements? | foo[6]; |
| A pointer variable pointing to the dynamic variable that was destroyed and becomes undefined. | dangling pointer |
| Which of the following is the proper keyword to allocate memory in C? | malloc |
| What is the output? #include <stdio.h> int main() { int a[3] = {1,2,3}; int *p = a; int **r = &p; printf("%d",++r); return 0; } | 1 |
| What is the output? #include <stdio.h> int main() { char *ptr = "Pointer to String", i; printf("%s",++ptr); return 0; } | ointer_to-string |
| Which of the following gives the memory address of integer variable a? | &a; |
| Given *p1=*p2, you are not dealing with the pointers p1 and p2 , but with the ______ to which the pointers are pointing. | variables |
| An array variable is not type int*, but its type is a const version of int*. | true |
| Reserved for dynamicallyallocated variables. | heap |
| The identifier NULL is defined in a number of libraries, including | iostream |
| What is the output? #include <stdio.h> int main() { int a[] = {1,2,3,4,5,6,7,8,9}; int *p = a + 1; int *q = a + 6; printf("%d" , q - p) return 0; } | 5 |
| C++ limits the number of array dimensions to two. | False |
| If you leave out the size declarator in an array definition: | You must provide an initialization list |
| Which of the following correctly declares an array? | int anarray[10]; |
| What is the output of the following code fragment: int[] y = new int[5]; y[0] = 34; y[1] = 88; System.out.println( y[0] + " " + y[1] + " " + y[5] ); | The program is defective and will not compile |
| Which of the following gives the value stored at the address pointed to by pointer a? | *a; |
| Which of the following gives the memory address of a variable pointed to by pointer a? | a; |
| What is the output? #include <stdio.h> int main(){ int *ptr, a = 5; ptr = &a; *ptr += 2; printf("%d, %d ", *ptr, a); return 0; } | 7, 7 |
| A Symbol used to determine the address of a variable or simple called the address-of-operator. | & |
| What is the output of the following code fragment: int ar[] = {2, 4, 6, 8}; ar[0] = 23; ar[3] = ar[1]; System.out.println( ar[0] + " " + ar[3] ); | 23 4 |
| What is the missing statement in the following which copies string x into string y void strcpy(char *x, char *y) { while (*y != "\0") /*missing statement */ *x = "\0" } | *x++ = *y++ |
| What is the output? #include <stdio.h> int main() { int a[3] = {1,2,3}; int *p = a; int **r = &p; printf("%p %p",*r, a); return 0; } | same address is printed |
| Which of the following declares an array of int named img? | int[] img; |
| What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; | An error will occur when the code runs |
| Which of the following is the proper declaration of a pointer? | int *x; |
| In pointer p the expression *(p+1) is equivalent to p[1] . | True |
| They are determined while the program is running | dynamic arrays |
| Given *p1=*p2, you are not dealing with the pointers p1 and p2 , but withthe ______ to which the pointers are pointing. | variables |
| Any "tricky" code where it is not immediately obvious what you are trying to accomplish, should have comments right above it or on the same line with it.The target of coding convention is to read statements in the language, organize them into "modules," f | False |
| The process of separating modules is called ____________. | decoupling |
| As per Java Code conventions what should be the maximum number lines per java file ? | 2000 |
| Subsequent components of the package name vary according to an organisation's own internal naming conventions | True |
| It's not easier to integrate modules that use a common consistent naming standard - less need to look up and cross-reference the different names that refer to the same thing | False |
| Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters | True |
| What is the order in which the public, private and protected instance fields should be declared , in a class? | public,private,protected |
| What is the maximum characters allowed per line in Java ,beyond of which a line break is considered a good practice ? | 80 |
| Clean code ____________. | is easy to understand and easy to change |
| One sometimes encounters Bad Coding Standards, arbitrarily imposed restrictions destructive to the development process, but that's the exception rather than the rule. | True |
| Variable names should be long yet meaningful | False |
| Every letter in a Java keyword is in lowercase | True |
| One-character variable names should not be avoided except for temporary variables | False |
| Methods should be verbs, in mixed case with the first letter lowercase and with the first letter of each internal word capitalised | True |
| As a programmer, you don't have to know how to organize programs for readability, as you would organize a book. | False |
| In programming, when you organize module, you can also apply information hiding. Meaning you Hide details of implementation that users don't need to know. | True |
| Documentation is not a dreadful waste of energy if applied in the wrong direction. | False |
| Comment the same way, format your code the same way | True |
| Projects benefit from having strong Coding Conventions/Standards because People can stop reformatting code and renaming variables and methods whenever working on code written by other people. | True |
| Variables Should be mnemonic i.e, designed to indicate to the casual observer the intent of its use | True |
| Which of the following comment should be used to give description about a class. | None of the above |
| Constant variables Should not be all uppercase with words separated by underscores ("_"). | False |
| Class names should be nouns, in mixed case with the first letter of each internal word capitalize | True |
| Never leave your catch block empty ? | True |
| self-documenting code is a Code that allegedly explains itself without the need of extraneous documentation, like flowcharts, UML diagrams, process-flow statediagrams, etc. | True |
| All the package names should be in lower case? | True |
| The target of coding convention is to read statements in the language, organize them into "modules," format them in the source files Aswell as how you properly create names and comments | False |
| Any "tricky" code where it is not immediately obvious what you are trying to accomplish, should have comments right above it or on the same line with it. | True |
| The prefix of a unique package name is not always written in all-lowercase ASCII letters and should be one of the top-level domain names, like com, edu, gov, mil, net, org. | False |
| Name your classes differently, your variables, your methods | False |