22
PART III : Language processing, interpretation, translation, the concept of binding, variables, name and scope, Type, l-value, r-value, reference and unnamed variables, routines, generic routines, aliasing and overloading, an abstractsemanticprocessor, run time structure. Casestudy- C run time structure ((MARKS)) (1/2/3...) 1 ((QUESTIO N)) Aliasing in the context of programming languages refers to ((OPTION_ A)) multiple variables having the same memory location ((OPTION_ B)) multiple variables having the same value ((OPTION_ C)) multiple variables having the same identifier ((OPTION_ D)) multiple uses of the same variable ((CORRECT _CHOICE)) (A/B/C/D) A ((EXPLANA TION)) (OPTIONAL ) Aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program. ((MARKS)) (1/2/3...) 1 ((QUESTIO N)) In the evaluation of a computer language, all of the following characteristics should be considered except? ((OPTION_ A)) Environment : S/w development tools

PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

PART III : Language processing, interpretation, translation, the concept of binding, variables, name and scope, Type, l-value, r-value, reference and unnamed variables, routines, generic routines, aliasing and overloading, an abstractsemanticprocessor, run time structure. Casestudy- C run time structure

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Aliasing in the context of programming languages refers to

(GATE CS 2000)

((OPTION_

A))

multiple variables having the same memory location

((OPTION_

B))

multiple variables having the same value

((OPTION_

C))

multiple variables having the same identifier

((OPTION_

D))

multiple uses of the same variable

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

Aliasing describes a situation in which a data location in

memory can be accessed through different symbolic names

in the program.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In the evaluation of a computer language, all of the

following characteristics should be considered except?

((OPTION_

A))

Environment : S/w development tools

Page 2: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((OPTION_

B))

Efficiency

((OPTION_

C))

readability

((OPTION_

D))

hardware maintainance costs

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation

((MARKS))

(1/2/3...)

2

((QUESTIO

N))

What is printed by the print statements in the program P1

assuming call by reference parameter passing?

((OPTION_

A))

10 , 3

((OPTION_

B))

31 , 3

((OPTION_

C))

27, 7

((OPTION_

D))

None of the above

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

Note the order in which parameters are passed. Inside

func1(), x will actually refer to y of main(); and y and z will

Page 3: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

(OPTIONAL

)

refer to x of main(). The Statement y = y + 4; will result in

14 and statement z = x + y + z will make z = 3 + 14 + 14 =

31 (because y and z point to same variable x of main).

Since z refers to x of main(), main will print 31.

((MARKS))

(1/2/3...)

2

((QUESTIO

N))

Consider the following program

Program P2

var n: int:

procedure W(var x: int)

begin

x=x+1;

print x;

end

procedure D

begin

var n: int;

n=3;

W(n);

end

begin //beginP2

n=10;

D;

end

If the language has dynamic scoping and parameters are

passed by reference, what will be printed by the program?

((OPTION_

A))

10

((OPTION_ 11

Page 4: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

B))

((OPTION_

C))

3

((OPTION_

D))

None of Above

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

Program will print 4.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

The- results returned by functions under value-result and

reference parameter passing conventions

((OPTION_

A))

Do not differ

((OTION_B)

)

Differ in the presence of loops

((OPTION_

C))

Differ in all cases

((OPTION_

D))

May differ in the presence of exceptions

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

In call-by-reference evaluation, a function receives an

implicit reference to the argument, rather than a copy of its

value. This typically means that the function can modify

Page 5: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

) the argument- something that will be seen by its caller.

Note that C doesn’t support call by reference but call-by-

reference can be implemented using pointers.

Call-by-value-result uses a combination of call-by-value

and call-by-reference. Call-by-value-result works by

creating local versions of the parameters passed in.

However, the values in these local versions are copied back

to the original arguments after the end of the procedure.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Values that are passed between program and its called

subroutine are classified as

((OPTION_

A))

parameter.

((OTION_B)

)

argument.

((OPTION_

C))

global values.

((OPTION_

D))

both a and b.

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

Page 6: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Program subroutines are

((OPTION_

A))

called by other programs.

((OTPION_

B))

fixed variable.

((OPTION_

C))

default constants.

((OPTION_

D))

default variables.

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

No Explanation

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Program routine which is used by one or more computer

programs is classified as

((OPTION_

A))

super-routine.

((OTPION_

B))

subroutine.

((OPTION_ dimension routine.

Page 7: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

C))

((OPTION_

D))

array routine.

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Program used for interactive computing is

((OPTION_

A))

Translator

((OTPION_

B))

Executor

((OPTION_

C))

Instructor

((OPTION_

D))

Interpreter

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

Page 8: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Program which translates high level program into machine

code is classified as

((OPTION_

A))

Compiler.

((OTPION_

B))

Translator.

((OPTION_

C))

Translating Analyst

((OPTION_

D))

instruction analst

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Dynamic binding takes place during

((OPTION_

A))

Translation

((OTPION_

B))

Linking

((OPTION_

C))

Loading the program

Page 9: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((OPTION_

D))

Execution

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Static binding takes placed during

((OPTION_

A))

Translation

((OTPION_

B))

Linking

((OPTION_

C))

Loading the program

((OPTION_

D))

All of the Above

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

Page 10: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In which of the following mechanisms, types of all

variables and expressions are fixed at compilation time.

((OPTION_

A))

Strong Typing

((OTPION_

B))

Weak Typing

((OPTION_

C))

Static Binding/ early binding

((OPTION_

D))

Dynamic Binding/ late binding

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In which of the following mechanisms, types of all

variables and expressions are not known until runtime

((OPTION_

A))

Strong Typing

((OTPION_

B))

Weak Typing

((OPTION_

C))

Static Binding/ early binding

Page 11: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((OPTION_

D))

Dynamic Binding/ late binding

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In which of the following mechanisms, types of all

variables and expressions are not known until runtime

((OPTION_

A))

Strong Typing

((OTPION_

B))

Weak Typing

((OPTION_

C))

Static Binding/ early binding

((OPTION_

D))

Dynamic Binding/ late binding

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

Page 12: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

What is the scope of an external variable?

((OPTION_

A))

Whole source file in which it is defined

((OTPION_

B))

From the point of declaration to the end of the file in which

it is defined

((OPTION_

C))

Any source file in a program

((OPTION_

D))

From the point of declaration to the end of the file being

compiled

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

What is the scope of a function?

((OPTION_

A))

Whole source file in which it is defined

((OTPION_

B))

From the point of declaration to the end of the file in which

Page 13: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

it is defined

((OPTION_

C))

Any source file in a program

((OPTION_

D))

From the point of declaration to the end of the file being

compiled

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Which variable has the longest scope?

#include <stdio.h>

int b;

int main()

{

int c;

return 0;

}

int a;

((OPTION_

A))

a

((OTPION_

B))

b

((OPTION_

C))

c

((OPTION_ Both a and b

Page 14: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

D))

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Scope of variable is related to definition of variable as:

1. Region of code within which variable value is valid and

hence can be accessed.

2. No, relation with region where variable is declared its

value is valid in entire scope.

((OPTION_

A))

1

((OTPION_

B))

2

((OPTION_

C))

Both 1 and 2

((OPTION_

D))

None

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

No Explanation for this question.

Page 15: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

(OPTIONAL

)

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Scope of variable is related to definition of variable as:

1. Region of code within which variable value is valid and

hence can be accessed.

2. No, relation with region where variable is declared its

value is valid in entire scope.

((OPTION_

A))

1

((OTPION_

B))

2

((OPTION_

C))

Both 1 and 2

((OPTION_

D))

None

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

A variable that receives an assigned value is called an

................

Page 16: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((OPTION_

A))

L-value

((OTPION_

B))

R-value

((OPTION_

C))

Value

((OPTION_

D))

Assignment

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Recursion is sometimes called ..................

((OPTION_

A))

Circular definition

((OTPION_

B))

Complex definition

((OPTION_

C))

Procedure

((OPTION_

D))

Union

((CORRECT

_CHOICE))

(A/B/C/D)

A

Page 17: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((EXPLANA

TION))

(OPTIONAL

)

No Explanation for this question.

((MARKS))

(1/2/3...)

2

((QUESTIO

N))

What will be the output of the following program?

#include<stdio.h>

int main()

{

int i = 10;

printf("%d", ++(-i));

return 0;

}

((OPTION_

A))

11

((OTPION_

B))

10

((OPTION_

C))

-9

((OPTION_

D))

None

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

In C/C++ the pre-increment (decrement) and the post-

increment (decrement) operators require an L-value

expression as operand. Providing an R-value or a const

qualified variable results in compilation error.

Page 18: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((MARKS))

(1/2/3...)

2

((QUESTIO

N))

What will be output if you will compile and execute the

following c code?

#define max 5;

void main(){

int i=0;

i=max++;

printf("%d",i++);

}

((OPTION_

A))

5

((OTPION_

B))

6

((OPTION_

C))

R-value required

((OPTION_

D))

L-value Required

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

It is clear macro constant max has replaced by 5. It is illegal

to increment the constant number. Hence compiler will

show Lvalue required.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Variable which uses same name in whole program and in

its all routines thus best classified as

((OPTION_ Middle variable

Page 19: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

A))

((OTPION_

B))

Global Variable

((OPTION_

C))

Local Variable

((OPTION_

D))

Default Varaible

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

No Explanation

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Use of recursion

((OPTION_

A))

enhances logical clarity

((OTPION_

B))

makes debugging easier

((OPTION_

C))

reduces execution time

((OPTION_

D))

reduces code size

((CORRECT

_CHOICE))

(A/B/C/D)

D

Page 20: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((EXPLANA

TION))

(OPTIONAL

)

No Explanation

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In which of the following parameter passing mechanism,

the actual argument has to be a variable?

((OPTION_

A))

Pass by value

((OTPION_

B))

Pass by result

((OPTION_

C))

Pass by value-result

((OPTION_

D))

Pass by reference

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

No Explanation

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

The generic type in a template function

Page 21: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((OPTION_

A))

must be T

((OPTION_

B))

Can be T

((OPTION_

C))

cannot be T for functions you create, but may be for C++'s

built-in functions

((OPTION_

D))

Cannot be T

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

((MARKS))

(1/2/3...)

((QUESTIO

N))

((OPTION_

A))

((OPTION_

B))

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

Page 22: PART III : Language processing, interpretation ... · Note that C doesn’t support call by reference but call-by-reference can be implemented using pointers. Call-by-value-result

((EXPLANA

TION))

(OPTIONAL

)