Programming Languages Final Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the output of the following C program void main() { int i; for(i=1;i<5;i++) { if(i==3) continue; printf("%d",i); } } A. 1245 B. 12345 C. 124 D. 12

124

If you enter 1 2 3, when you run this Java program, what will be the output? import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute average double average = (number1 + number2 + number3) / 3; // Display result System.out.println(average); } }

2.0

What is the value of (double)5/2 and (double)(5/2)?

2.5 and 2.0

Find the output of the given C program. #include<stdio.h> int main() { int a = 2; a += a += a += 3; printf("%d",a); return 0; }

20

What is the value of the expression 100 / 25 in python?

4.0

What would be the size of the following union declaration? union uTemp { double a; int b[10]; char c; }u; (Assuming size of double = 8, size of int = 4, size of char = 1)

40

What is i printed in the following Java code? public class Test { public static void main(String[] args) { int j = 0; int i = j++ + j * 5; System.out.println("What is i? " + i); } }

5

What is an expression in programming languages? A. A named storage location that holds a value B. A way to perform calculations in a program C. A block of code that is executed repeatedly D. A combination of operators and operands that evaluates to a value

A combination of operators and operands that evaluates to a value

Which of the following statements is true about the "loop-continuation-condition" statement in the for loop? A. It is evaluated before each execution of the loop body B. It is evaluated after each execution of the loop body C. It is evaluated only once before the loop starts D. It initializes the loop variable

A. It is evaluated before each execution of the loop body

Which of the following is the scope of a variable? A. The portion of the program in which the variable can be accessed B. The structure associated with the variable C. The type associated with the variable D. The number of characters in the variable's name

A. The portion of the program in which the variable can be accessed

Which of the following is true for variable names in C? A. Variable names cannot start with a digit B. Variable can be of any length C. It is not an error to declare a variable to be one of the keywords(like goto, static) D. They can contain alphanumeric characters as well as special characters

A. Variable names cannot start with a digit

Which one of the following is an example of explicit heap-dynamic variable? A. int *p = new int; B. int x; C. static int x; D. scores = [91, 92, 93];

A. int *p = new int;

Which of the following operator has highest Precedence in C? A. [ ] B. * C. / D. ~

A. [ ]

What is the output of the following Java code: double x = 5.5; int y = (int)x; System.out.println("x is " + x + " and y is " + y); A. x is 5.5 and y is 5 B. x is 6.0 and y is 6.0 C. x is 6 and y is 6 D. x is 5 and y is 6

A. x is 5.5 and y is 5

Which of the following statements about the switch statement in C is true? A. The default keyword is required in every switch statement B. Each case label must be unique C. The break statement is required after each case D. The switch statement can only be used with integers and characters

B. Each case label must be unique

Which of the following about binding is FALSE ____________? A. Storage binding can occur at compile time. B. Storage binding can only occur at runtime. C. Type binding can occur at compile time. D. Type binding can occur at runtime.

B. Storage binding can only occur at runtime.

The following code snippet in C contains an error (function name begins with a digit). int 5mult(int x, int y) { return(x*y); } This error is most likely to be classified as a:

B. syntax error detected by the parser

What is the range of signed char data type in C Programming? A. -32768 to 32767 B. -128 to 127 C. 0 to 65535 D. 0 to 255

B. -128 to 127

What is a binary operator? A. An operator that assigns a value to a variable B. An operator that works on two operands C. An operator that works on one operand D. An operator that works on three operands

B. An operator that works on two operands

Which of the following data types have a variable size ? A. int B. struct C. float D. double

B. struct

Named constants are used because __________

Because they make documentation and code modification easier

Size of a union is determined by size of the ___

Biggest member in the union

The precedence of arithmetic operators is (from highest to lowest) A. %, +, /, *, - B. %, +, -, *, / C. %, *, /, +, - D. +, -, %, *, /

C. %, *, /, +, -

Which is the least likely to be a task of the lexical analyzer? A. Collect characters into logical groupings B. Detect errors C. Build symbol table D. Remove whitespace

C. Build symbol table

What will happen if the below program is executed in C programming language? #include <stdio.h> int main() { int main= 3; printf ("%d", main); return 0; } A. It will cause a compile-time error B. It will cause a run-time error C. It will run without any error and prints 3 D. It will experience infinite looping

C. It will run without any error and prints 3

Which one of the variable types has static storage binding?

C. Static variable

Which of the following statements about posttest loops is true? A. Posttest loops are also known as while loops B. Posttest loops can only only be implemented using the for statement C. The loop condition is checked after executing the loop body D. The loop condition is checked before executing the loop body

C. The loop condition is checked after executing the loop body

Which of the following statements is true about the Control Expression in Java? A. can only be an arithmetic expression B. Neither a Boolean nor an arithmetic expression C. can only be a Boolean expression. D. can be either a Boolean or an arithmetic expression

C. can only be a Boolean expression.

_______ defines the order of evaluation when operators have the same precedence A. Priority B. Precedence C. Associativity D. None of the abov

C. Associativity

Which of the following is not a step in the process of translating a program? A. Lexical analysis B. Code generation C. Executing the program D. Parsing the program

C. Executing the program

Find the output of the given program? #include <stdio.h> int main() { const float pi = 3.14; pi = 3; printf("%f", pi); return 0; }

Compile-time Error

Which of the following is true of l-values and r-vlaues

D. An l-value refers to a variable's location while an r-value to its current value

which of the following is not correct about the aliases in programming languages? A. Having two names for the same memory cell B. Aliases are harmful to readability C. Aliases means two variable names can be used to access the same memory cell D. Aliases are created via pointers and reference variables in C

D. Aliases are created via pointers and reference variables in C

Which among the following is NOT a logical or relational operator? A. == B. != C. || D. =

D. =

For the statement: count = count + 5, count is a local variable When is the type of count bound? A. Language implementation time B. Run time C. Language design time D. Compile time

D. Compile Time

In the following code snippet in Java double area = 3.5; System.out.println(area); Which of following is false for "area" A. area is a named entity that is assigned a value during runtime B. area is a value that contains a decimal point C. The set of possible values of area is bound at compiler design time. D. The type of double is bound to area at run time.

D. The type of double is bound to area at run time.

To declare a constant MAX_LENGTH inside a method with value 99.98 in Java, you write A. const float MAX_LENGTH = 99.98; B. final MAX_LENGTH = 99.98; C. double MAX_LENGTH = 99.98; D. final double MAX_LENGTH = 99.98;

D. final double MAX_LENGTH = 99.98;

To assign a double variable d to a float variable x, you write A. x = d; B. x = (long)d C. x = (int)d; D. x = (float)d;

D. x = (float)d;

Which of the following cannot be a structure member? A. Another structure B. Function C. Array D. Union

Function

Which one of the following languages support dynamic type binding? _____________

Python

____ are words that a programming language has set aside for its own use.

Reserved Words

hat does a bottom-up parser generate?

Rightmost derivation in reverse

Consider the following process in memory. #include <stdio.h> #include <stdlib.h> int x; int y = 15; int main(int argc, char *argv[]) { int *values; int i; values = (int *)malloc(sizeof(int)*5); for(i = 0; i < 5; i++) values[i] = i; return 0; } The storage of variable i will be bound to ____

Runtime Stack

A variable's ________indicates where the variable can be used in an application code

Scope

What are the input and output for the lexical analyzer?

Source code and tokens

What is semantic analysis responsible for?

Static checking

________binding is used to define the scope in terms of the lexical structure of a program.

Static scope

The errors that can be pointed out by the compiler are known as ___

Syntax Errors

What happens in an assignment such as "x := y"? A. x and y become aliases B. The object bound to y is copied and bound to x, and any previous binding of x to an object is lost C. The address of x is modified to be the address of y D. The address of y is modified to be the address of x

The object bound to y is copied and bound to x, and any previous binding of x to an object is lost

In which parsing, the parser constructs the parse tree from the start symbol and transforms it into the input symbol.

Top-down parsing

What will be output when you will execute following c code? void main(){ int fruit=1; switch(fruit+2) { default:printf("apple"); case 4: printf(" banana"); case 5: printf(" orange"); case 8: printf(" grape"); } }

apple banana orange grape

Which is correct with respect to size of the datatypes? A. double > char > int B. char > int > float C. int > char > float D. char < int < double

char < int < double

Which keyword is used to declare a named constant in C++?

const

If you attempt to add an int, a byte, a long, and a double, the result will be a(n) __________ value.

double

Which of the following is an example of a counter-controlled loop in most programming languages? A. switch statement B. while loop C. for loop D. do-while loop

for loop

What is the number of bytes in memory taken by the following structure? struct test { int k; char c; }; A. Multiple of integer size B. integer size+character size C. Depends on the platform D. Multiple of word size

integer size+character size

Which of the following is false for the type of a variable A. determines the range of values the variable can store B. can be used to catch some errors early C. can be statically or dynamically D. only matters for integer types

only matters for integer types

In the Python statement x = a + 5 - b: a and b are ________ a + 5 - b is ________

operands and expression

The lifetime of the static variables in a C program is ____

till the end of the main program


Ensembles d'études connexes

Carbon Cycle Unit Test (Progress Learning)

View Set

chapter 12 nervous system , notes

View Set

Chapter 5: Market your Business *Chapter Overview pg.141 - 142 (1 - 25) *a.l.o

View Set

Mental Health Nursing - Chapter 17 - Somatic symptom disorders

View Set

QB25__WORD_FORMATION_SENTENCES_201_TO_300

View Set

Principals of Entrepreneurship - Final Exam

View Set