TCS Functions and scope Questions Quiz-1

Question 1

Time: 00:00:00
What is the difference between a function and a method?

A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed. A method is a piece of code that is called by a name that is associated with an object.

A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed. A method is a piece of code that is called by a name that is associated with an object.

A method is a piece of code that is called by a name that is associated with an object.

A method is a piece of code that is called by a name that is associated with an object.

A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.

A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.

None of these

None of these

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

PrepInsta User

Function can be called by its name whereas method cannot

PrepInsta User

A is an answer

PrepInsta User

A

PrepInsta User

A

PrepInsta User

Function can be called by its name whereas method cannot

PrepInsta User

c

Start

Question 2

Time: 00:00:00
Consider the following code:

function modify(a,b)
{
integer c, d = 2
c = a*d + b
return c
}

function calculate( )
{
integer a = 5, b = 20, c
integer d = 10
c = modify(a, b);
c = c + d
print c
}

80

80

40

40

32

32

72

72

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

PrepInsta User

The answer is 40

PrepInsta User

The answer is 4

Start

Question 3

Time: 00:00:00
What is the term given to the variable whose scope is beyond all the scopes i.e., it can be accessed by all the scopes?

Universal Variable

Universal Variable

Global Variable

Global Variable

External Variable

External Variable

Auto Variable

Auto Variable

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

PrepInsta User

Global Variable

PrepInsta User

Global variable

PrepInsta User

Global variable

Start

Question 4

Time: 00:00:00
Anu wants to make a function that is not bound to any identifier. Which of the following functions should she incorporate in her program?

Global Function

Global Function

Null function

Null function

Anonymous Function

Anonymous Function

Friend Function

Friend Function

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

PrepInsta User

anonymous function is associated with predefined function so there is no need to associate any identifier with it .

PrepInsta User

Friend function

PrepInsta User

its anonymous function becz ..that is not bound to any of the identifier

PrepInsta User

global

Start

Question 5

Time: 00:00:00
Which of the following accessibility modes can be the specifier of a top level class’?Top-level classes can only have public, abstract, and final modifiers, and it is also possible to not define any class modifiers at all. This is called default/package accessibility. Besides that, private, protected, and static modifiers cannot be used when declaring top-level classes.

 

 

Only Private

Only Private

Protected and Private

Protected and Private

Public and No Modifier

Public and No Modifier

Only No Modifier

Only No Modifier

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-explanatory An accessible member function or data member for an object are accessed by the statement objectname.functionname or objectname. data member name respectively.

class brush
{

Private:
integer size, colorcode
function getdata( ) {--}//Statement 1
public:
integer name // Statement 2
function putdata(){...}
}

function main
{

brush b1, b2
print bl.name //Statement 3
b2.getdata() //Statement 4
}

Deleting which line will correct the error in the code?

Statement 1

Statement 1

Statement 2

Statement 2

Statement 3

Statement 3

Statement 4

Statement 4

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

PrepInsta User

but we can access via the object of respective class

Start

Question 7

Time: 00:00:00
function MyDisplay(string MyStr) //statement 1
{
print "Hello !"
print MyStr
return 1 // statement 2
}
function main() //statement 3
{
string str= "Mickey"
MyDisplay(str) // statement 4
}

Which statement will generate an error.

Statement 1

Statement 1

Statement 2

Statement 2

Statement 3

Statement 3

Statement 4

Statement 4

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

PrepInsta User

that return interger but function accept only string

PrepInsta User

it might be statement 2 also wrong .but statement is confirmed wrong because it has return value and does not defined in the function MyDisplay();

PrepInsta User

In function returning 0 means success. Other values like 1 or -1 resembles error or faliure.

PrepInsta User

Since return 1, does not make any sense here.

PrepInsta User

in statement 2 and statement 4 there is an error , because in statement 2 a return statemnt is present which will executed.

Start

Question 8

Time: 00:00:00
Choose the correct answer
Tanuj writes the code for a function that takes as input n and calculates the sum of first n natural numbers.

Function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}

Fill in ?? in the code.

n equals 1

n equals 1

n equals 2

n equals 2

n>=1

n>=1

n>=2

n>=2

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
Choose the correct answer
Shrishti writes the code for a function that computes the factorial of the inputted number n.

function factorial(n)
{
if(n equals 1)
return 1
else
— MISSING STATEMENT —
end
}

Fill in the missing statement.

return factorial(n-1)

return factorial(n-1)

return n*factorial(n)

return n*factorial(n)

return n*(n-1)

return n*(n-1)

return n*factorial(n-1)

return n*factorial(n-1)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
What is the output of this C code?

#include <stdio.h>
int main() {
int y = 10000;
int y = 34;
printf(“Hello World! %d\n”,y);
return 0;
}

Compile time error

Compile time error

Hello World! 34

Hello World! 34

Hello World! 1000

Hello World! 1000

Hello World! followed by a junk value

Hello World! followed by a junk value

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice! \r\n \r\n","Keep trying! \r\n \r\n","Not bad! \r\n \r\n","Good work! \r\n \r\n","Perfect! \r\n \r\n"]

Buy TCS Prog. Logic (C MCQ) Paid Materials

Join TCS Online Classes

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assurance

Get Access to PrepInsta Placement Cell

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

Comments

2 comments on “TCS Functions and scope Questions Quiz-1”