0

programming languages Online Quiz - 27

Description: programming languages Online Quiz - 27
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Default layout for frame

  1. Flow Layout

  2. GridLayout

  3. Card Layout

  4. BorderLayout

  5. GridBagLayout


Correct Option: D

Check whether the syntax of the piece of code is correct: text.setBackGround(color.Yellow);

  1. True

  2. False


Correct Option: B

Code: FILE *f = fopen( fileName, "r" ); readData( f ); if( ???? ) { puts( "End of file was reached" ); } Which one of the following can replace the ???? in the code above to determine if the end of a file has been reached?

  1. f == EOF

  2. feof( f )

  3. eof( f )

  4. f == NULL


Correct Option: A
Explanation:

To determine if the end of a file has been reached, we need to check the return value of the read operation. In the given code, the file is opened using fopen and then readData is called to read from the file. After that, we need to check if the end of the file has been reached.

Option A) f == EOF - This option is correct because it checks if the file pointer f is equal to the constant EOF (End of File). If the end of the file has been reached, the read operation will return EOF, and this condition will evaluate to true.

Option B) feof(f) - This option is incorrect. The feof function is used to check if the end-of-file indicator is set for the given file stream. It does not directly indicate if the end of the file has been reached after a read operation.

Option C) eof(f) - This option is incorrect. The eof function is not a standard function in C. It is not used to check if the end of a file has been reached.

Option D) f == NULL - This option is incorrect. The f pointer is obtained from fopen and is checked for NULL to ensure that the file was successfully opened. It does not indicate if the end of the file has been reached.

The correct answer is Option A) f == EOF. This option correctly checks if the end of the file has been reached after a read operation.

Therefore, the correct answer is Option A.

Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?

  1. int *ptr = (int *) malloc(10, sizeof(int));

  2. int *ptr = (int *) calloc(10, sizeof(int));

  3. int *ptr = (int *) malloc(10*sizeof(int));

  4. int *ptr = (int *) alloc(10*sizeof(int));


Correct Option: C

AI Explanation

To answer this question, you need to understand memory allocation in C.

Let's go through each option to understand why it is correct or incorrect:

Option A) int *ptr = (int *) malloc(10, sizeof(int)); This option is incorrect because the malloc function takes only one argument, which is the number of bytes to allocate. The correct syntax would be malloc(10*sizeof(int)) instead of malloc(10, sizeof(int)).

Option B) int *ptr = (int *) calloc(10, sizeof(int)); This option is correct. The calloc function allocates memory for an array of elements and initializes them to zero. It takes two arguments: the number of elements to allocate and the size of each element. In this case, calloc(10, sizeof(int)) allocates enough space for 10 integers and initializes them to 0.

Option C) int *ptr = (int *) malloc(10*sizeof(int)); This option is correct. The malloc function allocates memory for an array of elements without initializing them. It takes one argument: the number of bytes to allocate. In this case, malloc(10*sizeof(int)) allocates enough space for 10 integers.

Option D) int *ptr = (int *) alloc(10*sizeof(int)); This option is incorrect because there is no standard function called alloc() in C. The correct function to use for memory allocation is malloc().

The correct answer is Option C. This option allocates enough space to hold an array of 10 integers that are initialized to 0.

Which one of the following C operators is right associative?

  1. =

  2. ,

  3. []

  4. ->


Correct Option: A

Code: #include int i; void increment( int i ) { i++; } int main() { for( i = 0; i < 10; increment( i ) ) { } printf("i=%d\n", i); return 0; } What will happen when the program above is compiled and executed?

  1. It will not compile.

  2. It will print out: i=9.

  3. It will print out: i=10.

  4. It will loop indefinitely


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) It will not compile. This option is incorrect. The code provided will compile without any errors.

Option B) It will print out: i=9. This option is incorrect. The program will not print "i=9" because the increment function is not modifying the global variable i. It is modifying a local variable i within the function.

Option C) It will print out: i=10. This option is incorrect for the same reason as Option B. The local variable i within the increment function is being modified, not the global variable i.

Option D) It will loop indefinitely. This option is correct. The program will enter an infinite loop because the increment function is called within the for loop condition, but it is not actually modifying the global variable i. Therefore, i will always remain 0, and the condition i &lt; 10 will always be true.

The correct answer is D. It will loop indefinitely because the increment function is not modifying the global variable i.

char ** array [12][12][12]; Consider array, defined above. Which one of the following definitions and initializations of p is valid?

  1. char ** (* p) [12][12] = array;

  2. char ***** p = array;

  3. char * (* p) [12][12][12] = array;

  4. const char ** p [12][12][12] = array;


Correct Option: A
Explanation:

To solve this question, the user needs to be familiar with C/C++ syntax and the concept of pointers.

A. char ** (* p) [12][12] = array;

This option is valid. p is a pointer to a 3D array of char pointers. It is initialized to point to the first element of the array using the assignment operator =.

B. char ***** p = array;

This option is not valid. p is a pointer to a pointer to a pointer to a pointer to a pointer to a char, which is not compatible with the type of array.

C. char * (* p) [12][12][12] = array;

This option is not valid. p is a pointer to a 4D array of char pointers, which is not compatible with the type of array.

D. const char ** p [12][12][12] = array;

This option is not valid. p is a 3D array of const char pointers, which is not compatible with the type of array.

Therefore, the only valid option is:

The Answer is: A

Code: char *ptr; char myString[] = "abcdefg"; ptr = myString; ptr += 5; What string does ptr point to in the sample code above?

  1. efg

  2. cdefg

  3. fg

  4. None of the above


Correct Option: C
Explanation:

To solve this question, the user needs to understand the concept of pointers in C programming. In this case, ptr is a pointer variable that points to the first character of the myString array. The statement ptr += 5 increments the pointer by 5, so that it now points to the sixth character in the array.

Option A is incorrect because ptr is pointing to the sixth character in the array, not the third.

Option B is incorrect because ptr is pointing to the sixth character in the array, not the first.

Option C is correct because ptr is pointing to the sixth character in the array, which is "f", and continues to the end of the string, "g". Therefore, the string that ptr points to is "fg".

Option D is incorrect because an answer was provided above.

Therefore, the answer is: C. fg

time_t t; Which one of the following statements will properly initialize the variable t with the current time from the sample above

  1. t = ctime();

  2. time( &t );

  3. t = localtime();

  4. t = clock();


Correct Option: D

AI Explanation

To properly initialize the variable t with the current time, you can use the time() function from the ctime library.

Option A) t = ctime(); - This option is incorrect because the ctime() function returns a string representation of the current time, not the actual time value.

Option B) time( &amp;t ); - This option is correct because it calls the time() function and passes the address of t as an argument, allowing time() to store the current time value in t.

Option C) t = localtime(); - This option is incorrect because the localtime() function converts a time value into a broken-down time structure, not the current time.

Option D) t = clock(); - This option is incorrect because the clock() function measures the processor time, not the current time.

The correct answer is Option B.

Code: char* myFunc (char *ptr) { ptr += 3; return (ptr); } int main() { char *x, *y; x = "HELLO"; y = myFunc (x); printf ("y = %s \n", y); return 0; } What will print when the sample code above is executed?

  1. y = LLO

  2. y = LO

  3. y = ELLO

  4. y = HELLO


Correct Option: B

int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; What number will z in the sample code above contain?

  1. 12

  2. 10

  3. 11

  4. 6


Correct Option: B

AI Explanation

To find the value of z in the given code, let's break down the expression step by step:

  1. x++ increments the value of x by 1 after it is used in the expression. So, the value of x is now 6.

  2. --y decrements the value of y by 1 before it is used in the expression. So, the value of y is now -11.

  3. y * b multiplies the value of y (-11) by the value of b (2), resulting in -22.

  4. -22 / a divides the value of -22 by the value of a (4), resulting in -5.5.

  5. Finally, z = 6 - (-5.5), which simplifies to z = 6 + 5.5. Therefore, z equals 11.5.

However, since the given variables are integers, the result will be truncated to the nearest integer. So, z will contain the value 11.

Therefore, the correct answer is option C) 11.

What number is equivalent to -4e3?

  1. -400

  2. .004

  3. -4000

  4. .0004


Correct Option: C
Explanation:

To solve this question, the user needs to know the concept of scientific notation. In scientific notation, a number is expressed as the product of a coefficient and a power of 10. The coefficient is a number between 1 and 10, and the power of 10 represents the number of places the decimal point must be moved to obtain the original number.

The notation -4e3 means -4 times 10 to the power of 3, or -4 multiplied by 1000. This gives us -4000.

Now, let's go through each option and explain why it is right or wrong:

A. -400: This option is incorrect because -400 is not equal to -4e3. A negative exponent in scientific notation represents a number less than 1, so -4e3 is a negative number with a large absolute value.

B. .004: This option is incorrect because .004 is not equal to -4e3. A positive exponent in scientific notation represents a large number, so -4e3 is a negative number with a large absolute value.

C. -4000: This option is correct. As explained earlier, -4e3 means -4 times 10 to the power of 3, or -4 multiplied by 1000. This gives us -4000.

D. .0004: This option is incorrect because .0004 is not equal to -4e3. A positive exponent in scientific notation represents a large number, so -4e3 is a negative number with a large absolute value.

Therefore, the answer is:

The Answer is: C

Which one of the following is not written in Delphi?

  1. Skype

  2. Toad

  3. PL/SQL Developer

  4. MySQL

  5. MySQL Administrator


Correct Option: D

Find out the odd one.

  1. Embarcadero

  2. CodeGear

  3. Inprise

  4. Borland

  5. Pascal


Correct Option: E

Which compiler directive controls whether the reserved word 'string' represents a short string or a long string?

  1. $M+/-

  2. $H+/-

  3. $P+/-

  4. $V+/-

  5. $X+/-


Correct Option: B

Ultimate base class of all Objects and Components.

  1. TObect

  2. TUnknown

  3. IUnknown

  4. TBase

  5. TComponent


Correct Option: A

Components can only be allocated on the -----

  1. Stack

  2. Heap

  3. Register

  4. Floppy

  5. Compact Disk


Correct Option: B

Property can be pass as a var parameters. Judge the statement.

  1. TRUE

  2. True using pointer

  3. FALSE

  4. Some times true, some times false.


Correct Option: C

What is the ordinal value of 'nodefault' storage specifier of a property?

  1. 2147483647

  2. -2147483647

  3. 0

  4. 2147483648

  5. -1


Correct Option: D

TButton caption can be left aligned. Judge the comment.

  1. TRUE

  2. FALSE

  3. True with the help of changing the Bidi alignment.

  4. True by setting proper margin value.


Correct Option: B
- Hide questions