0

programming languages Online Quiz - 104

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

A function call is always an rvalue. True or false?

  1. True

  2. False


Correct Option: B

In namespace foo, the function bar can access the variable x also declared in namespace foo? #include namespace foo { void bar() { x++; } int x; } int main(int argc, char** argv) { return 0; }

  1. True

  2. False


Correct Option: B

What is the value of y at the end of main? const int x = 5; int main(int argc, char** argv) { int x[x]; int y = sizeof(x) / sizeof(int); return 0; }

  1. 0

  2. 5

  3. undefined

  4. 2


Correct Option: B

AI Explanation

To determine the value of y at the end of main, let's go through the code step by step:

const int x = 5;
int main(int argc, char** argv)
{
    int x[x];
    int y = sizeof(x) / sizeof(int);
    return 0;
}

In this code, we have a constant integer x initialized with the value of 5.

Next, we declare an array x with the size of x, which is 5. This means we are declaring an array with 5 elements.

Then, we calculate the value of y by dividing the size of the array x (which is 5 * sizeof(int)) by the size of an int (sizeof(int)).

The sizeof operator returns the size of a data type in bytes. In this case, sizeof(int) returns the size of an int in bytes.

Since the size of an int is typically 4 bytes, the size of the array x is 20 bytes (5 * 4).

Therefore, y is equal to the size of the array x (20 bytes) divided by the size of an int (4 bytes), which is 5.

Hence, the correct answer is B) 5.

what is the output of the programme? #define ABC 20 #define XYZ 10 #define XXX ABC - XYZ void main() { int a; a = XXX * 10; printf("%d ", a); }

  1. 20

  2. 10

  3. 100

  4. -80


Correct Option: D

AI Explanation

To determine the output of the given program, let's go through each line of code:

  1. #define ABC 20 - This line defines a macro ABC with the value 20.
  2. #define XYZ 10 - This line defines a macro XYZ with the value 10.
  3. #define XXX ABC - XYZ - This line defines a macro XXX which is equal to the value of ABC minus XYZ. Substituting the values, XXX becomes 20 - 10, which is 10.
  4. void main() - This line declares the main function.
  5. int a - This line declares an integer variable 'a'.
  6. a = XXX * 10 - This line assigns the value of XXX multiplied by 10 to the variable 'a'. Substituting the value of XXX, the expression becomes a = 10 * 10, which is 100.
  7. printf("%d ", a); - This line prints the value of 'a' using the printf function.

Therefore, the output of the program will be "100".

The correct answer is C) 100.

what is the output? int a = 400; void main() { int b; b=(400 * 400)/ a ; printf("%d",b); }

  1. compilation error

  2. garbage value

  3. 400

  4. 1


Correct Option: B

Print the output of this program main() { int k = 5; if (++k < 5 && k++/5 || ++k <= 8); printf("%d\n", k); }

  1. 5

  2. 7

  3. 8

  4. garbage value


Correct Option: B
Explanation:

To solve this question, we need to understand the order of operations and logical operators.

The given program uses the if statement to check some conditions. If the conditions are met, it increases the value of k. Finally, it prints the value of k using printf.

The given expression can be broken down into three parts:

  1. ++k < 5
  2. k++/5
  3. ++k <= 8

Let's evaluate each part:

  1. ++k < 5: The value of k is first incremented to 6. Then, this expression checks if 6 is less than 5. This is false, so the expression evaluates to false.

  2. k++/5: The value of k is still 6. This expression divides 6 by 5 (integer division), which evaluates to 1. However, this expression is not used in the if statement because of short-circuiting.

  3. ++k <= 8: The value of k is now 7 (due to the previous increment). This expression checks if 7 is less than or equal to 8. This is true, so the expression evaluates to true.

Since the expression in the if statement evaluates to true, the code inside the if statement is executed. This code does nothing, so k remains 7. Finally, the value of k is printed using printf.

Therefore, the output of this program is:

7

The answer is: B. 7

What is the result Integer i1=10; Integer i2=10; (i1==i2)-->result of this

  1. True

  2. False


Correct Option: A

What is result of the question Integer i1=10; Integer i2=10; (i1!=i2)-->result is

  1. True

  2. False


Correct Option: A

What is the result of this Integer i1=10; int i2=10; (i1==i2)-->result is

  1. True

  2. False


Correct Option: A

What is the result os this String s1="hi"; String s2="hi"; (s1==s2)-->returns

  1. true

  2. false

  3. compilation error

  4. exception thrown at runtime


Correct Option: A

String s1=new String("abc"); String s2=new String("abc"); (s1==s2)-->result is

  1. true

  2. false

  3. compilation error

  4. exception thrown at runtime


Correct Option: B

Integer i1=10; Integer i2=10; (i1.equals(i2++))-->result is

  1. true

  2. false

  3. compilation error

  4. exception thrown at runtime


Correct Option: B
  1. Language Integrated Query

  2. Language Independent Query

  3. Language Interrelated Query

  4. None of the above


Correct Option: A

In which version of .Net framework LINQ has been introduced

  1. 2.0

  2. 3.0

  3. 3.5

  4. 4.0


Correct Option: C

Features of LINQ

  1. Querying of in-memory collections

  2. Abstraction layer of data sources

  3. Object and Collection Initializers

  4. Lambda expressions


Correct Option: A,B,C

Features of LINQ

  1. Querying of in-memory collections

  2. Abstraction layer of data sources

  3. Object and Collection Initializers

  4. Lambda expressions


Correct Option: A,B,C

List Names = new List(); Names.Add("A"); Names.Add("B"); Names.Add("C"); var res = Names.Where(n => n == "D"); if (res == null) Console.WriteLine("res is null"); else Console.WriteLine("res is not null"); Console.Read(); What would be printed?

  1. res is null

  2. res is not null

  3. Run time error

  4. None of the above


Correct Option: B

List Names = new List(); Names.Add("A"); Names.Add("B"); Names.Add("C"); var res = Names.Where(n => n == "D"); res is the type of

  1. List

  2. IEnumerable

  3. List

  4. IEnumerable


Correct Option: B

Anonymous Types is a feature of LINQ

  1. True

  2. False


Correct Option: B

What will happen when you attempt to compile and run the following code? int Output = 10; boolean b1 = false; if((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); }

  1. Compilation and output of "Not equal! 10".

  2. Compilation and output of "Not equal! 20".

  3. Compilation and output of "We are equal 10".

  4. Compilation error, attempting to perform binary comparison on logical data type.


Correct Option: A
- Hide questions