wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

TCS NQT Coding Test-4

Total questions: 75

Worksheet time: 2hrs 43mins

Name
Class
Date
1.

What is the result of following Program in python3

a=4

b=2

c=a-b*6

print("\n a={0} \n b={1} \n c={2}".format(a,b,c))

a)

12

b)

-8

c)

8

d)

-12

2.

What is the result of following Program in python3

for i in range(3,0,-1)

print("{0} Python".format(i))

a)

3 Python

2 Python

1 Python

b)

2 Python

1 Python

0 Python

c)

3 Python

d)

error

3.

What is the result of following Program in python3

if(32%2==0):

print("32")

else:

print("2")

a)

2

b)

32

c)

error

4.

What is the result of following Program in python3

for i in range(3,1):

print(i)

a)

3

2

b)

3

2

1

c)

error

d)

2

1

0

5.

What is the result of following Program in python3

for i in range(1,4):

print(i)

if(i==2):

break;

a)

1

b)

1

2

c)

1

2

3

4

d)

error

6.

What is the result of following Program in python3

for i in range(1,4):

print(i)

if(i==2):

continue;

a)

1

b)

1

2

3

c)

error

d)

1

3

7.
The Python code below is an example of which programming term?
person = input('Enter your name: ')
print('Hello', + person)
a)
concatenation
b)
algorithm
c)
conditional
d)
loop
8.
The Python code below is an example of which programming term?
x = int(input("Please enter an integer: "))
if x<0:
  x=0
  print("Your negative number was changed to zero")
a)
concatenation
b)
algorithm
c)
conditional
d)
loop
9.
For which programming language is the "hello world" code below written?
hello world
a)
HTML
b)
JavaScript
c)
Python
d)
C#
10.
For which programming language is the "hello world" code below written?
document.write('hello world');
a)
HTML
b)
JavaScript
c)
Python
d)
C#
11.
For which programming language is the "hello world" code below written?

using System;
class Program
{
  public static void Main(string[] args)
  {
  Console.WriteLine("Hello, world!");
  }
}
a)
HTML
b)
JavaScript
c)
Python
d)
C#
12.
For which programming language will inconsistent indentation cause a syntax error?
a)
HTML
b)
JavaScript
c)
Python
d)
C#
13.

If a=(1,2,3,4), a[1:-1] is _________

a)

a) Error, tuple slicing doesn’t exist

b)

b) [2,3]

c)

c) (2,3,4)

d)

d) (2,3)

14.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

a) [2, 33, 222, 14]

b)

b) Error

c)

c) 25

d)

d) [25, 14, 222, 33, 2]

15.

What is the order of precedence in python?

a)

a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

16.

Which of the following functions is a built-in function in python?

a)

a) factorial()

b)

b) print()

c)

c) seed()

d)

d) sqrt()

17.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

18.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

19.

What will be the output of the following Python code?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a)

a) olleh

b)

b) hello

c)

c) h

d)

d) o

20.

What will be the output of the following Python code?

>>>str1="helloworld"

>>>str1[::-1]

a)

a) dlrowolleh

b)

b) hello

c)

c) world

d)

d) helloworld

21.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

22.

Which of the following statements create a dictionary?

a)

a) d = {}

b)

b) d = {“john”:40, “peter”:45}

c)

c) d = {40:”john”, 45:”peter”}

d)

d) All of the mentioned

23.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

d["john"]

a)

a) 40

b)

b) 45

c)

c) “john”

d)

d) “peter”

24.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b)

b) Method update() doesn’t exist for dictionaries

c)

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d)

d) {4: ‘D’, 5: ‘E’}

25.

Find the output of the following:-

int sum=0, n=10;

for( int i=n; i>=1; -- i)

{ sum= sum+ i; }

System.out.println(" Sum is "+ sum) ;

a)

55

b)

10

c)

28

d)

50

26.

Consider these functions:

push() : push an element into the stack

pop() : pop the top-of-the-stack element

top() : returns the item stored in top-of-the-stack-node

What will be the output after performing these sequence of operations


push(20);

push(4);

top();

pop();

pop();

pop();

push(5);

top();

a)

20

b)

4

c)

5

d)

Stack Underflow

27.

what is the ouput of the below program?


int main()

{

int i=10, j=20;

if((i=100) && (j==20))

{

printf("Have a nice day");

}

else

{

printf("condition not true");

}


return 0;

}

a)

No output

b)

Have a nice day

c)

condition not true

d)

Complier Error

28.

What is the output here:


#include <stdio.h>


int main()

{

int i = 1, 2, 3;

printf("%d", i);

return 0;

}

a)

1

b)

2

c)

3

d)

Compilation Error

29.

What is the output of the below program?


#include <stdio.h>

int main()

{

int i = 0;

switch (i)

{

case '0': printf("Enrich");

break;

case '1': printf("Grow");

break;

default: printf("EnrichnGrow");

}

return 0;

}

a)

Enrich

b)

Grow

c)

EnrichnGrow

d)

Compile Time error

30.

what is the output?


#include<stdio.h>

int main()

{

int n;

for (n = 9; n!=0; n--)

printf("n = %d", n--);

return 0;

}

a)

n=9 n=7 n= 5 n=3 n=1

b)

n=9 n=8 n=7 n=6 n=5 n=4 n=3 n=2 n=1

c)

Infinite loop

d)

n=9 n=7 n= 5 n=3

31.

How many times do while loop is guaranteed to execute?

a)

0

b)

1

c)

depends upon condition

d)

No gurantee

32.

What is the final value of x when following code is run?

int x;

For(x=0;x<10;x++)

{

Printf(“%d”,x);

}

a)

9

b)

10

c)

0

d)

8

33.

What is the output ?

int var;

var = !(0 && (2||1));

printf("%d",var);

a)

0

b)

2

c)

1

d)

Compiler Error

34.

what is the value of j displayed ?

#include <stdio.h>


int i=9;

int j=0;


int main()

{

int i=10;

i++;

j=i;

printf("value of j is %d", j);

return 0;

}

a)

9

b)

10

c)

11

d)

0

35.

What is the output?

#include <stdio.h>

int main()

{

int i;

for (i = 1; i != 10; i += 2)

printf(" QuizC ");

return 0;

}

a)

QuizC QuizC QuizC QuizC QuizC

b)

QuizC QuizC QuizC …. infinite times

c)

QuizC QuizC QuizC QuizC

d)

QuizC QuizC QuizC QuizC QuizC QuizC

36.

The value of j at the end of the execution of the following C program:

int incr(int i)

{

static int count=0;

count=count+i;

return(count);

}

main()

{

int i,j;

for(i=0;i<=4;i++)

j=incr(i);

}

a)

10

b)

4

c)

6

d)

7

37.

Consider the following C declaration :

struct {

short s[5]

union{

float y;

long z;

}u;

}t;

Assuming that objects of the type short,float and long occupy 2 bytes,4 bytes and 8 bytes respectively. The memory requirement for variable t, ignoring alignmenmt considerations, is :

a)

22 bytes

b)

18 bytes

c)

14 bytes

d)

10 bytes

38.

What will be the output of the following C program segment ?

char inchar='A';

switch(inchar)

{

case\\\'A\\\'n:

printf("choice A\\\n");

case\\\'B\\\';

printf("choice B");

case\\\'C\\\';

case\\\'D\\\';

case\\\'E\\\';

Default :

printf("No Choice");

}

a)

No Choice

b)

Choice A

c)

Choice A Choice B No Choice

d)

Program gives no output as it is erroneous

39.

Consider the following C program

main()

{

int x,y,m,n;

scanf("%d%d",&x,&y);

/* x>0 and y>0 */

m=x;n=y;

while(m!=n)

{

if(m>n)

m=m-n;

else

n=n-m;

}

printf("%d",n);

}

a)

x+y using repeated subtraction

b)

x mod y using repeated subtraction

c)

the greatest common divisior of x and y

d)

the least common multiple of x and y

40.

Consider the following C function :

int f(int n)

{

static int i=1;

if(n>=5)

return n;

n=n+i;

i++;

return f(n);

}

The value return by f(1) is

a)

5

b)

6

c)

7

d)

8

41.

Consider the following C function :

void swap(int a,int b)

{

int temp;

temp=a;

a=b;

b=temp;

}

In order to exchange the value of two variable x and y:

a)

call swap(x,y)

b)

call swap(&x,&y)

c)

swap(x,y) cannot be used as it does not return any value

d)

swap(x,y) cannot be used as the parameters are passed by value

42.

What does the following fragment of C program print?

char c[]="GATE2011";

char *p=c;

printf("%s",p+p[3]-p[1];

a)

GATE2011

b)

E2011

c)

2011

d)

011

43.

Consider the following C program segment:

char p[20];

char*s="string";

int length=strlen(s);

int i;

for(i=0;i<length;i++)

p[i]=s[length-i];

printf("%s",p);

The output of the program is :

a)

gnirts

b)

gnirt

c)

string

d)

No output

44.

Consider the following recursive C function that takes two arguments

unsigned int foo(unsigned int n,unsigned int r)

{if(n>0) return (n%r+foo(n/r,r));

else return 0;

What is the value of foo(513,2)

a)

9

b)

8

c)

5

d)

2

45.

What is the range of values that can be stored by int datatype in C?

a)

-(2^31) to (2^31) - 1

b)

-256 to 255

c)

-(2^63) to (2^63) - 1

d)

0 to (2^31) - 1

46.

What will be the output of the following code snippet?

#include <stdio.h>

int main() {

        int a = 3, b = 5;

        int t = a;

        a = b;

        b = t;

        printf("%d %d", a, b);

        return 0;

}

a)

3 5

b)

3 3

c)

5 5

d)

5 3

47.

How is an array initialized in C language?

a)

int a[3] = {1, 2, 3};

b)

int a = {1, 2, 3};

c)

int a[] = new int[3]

d)

int a(3) = [1, 2, 3];

48.

What is the output of the following code snippet?

#include <stdio.h>

int main() {

        int a[] = {1, 2, 3, 4};

        int sum = 0;

        for(int i = 0; i < 4; i++) {

            sum += a[i];

        }

        printf("%d", sum);

        return 0;

}

a)

1

b)

4

c)

20

d)

10

49.

What is the output of the following code snippet?

int main() {

        int sum = 2 + 4 / 2 + 6 * 2;

        printf("%d", sum);

        return 0;

}

a)

2

b)

15

c)

16

d)

18

50.

How is the 3rd element in an array accessed based on pointer notation?

a)

*a + 3

b)

*(a + 3)

c)

(a + 3)

d)

&(a + 3)

51.

How are String represented in memory in C?

a)

An array of characters.

b)

The object of some class.

c)

Same as other primitive data types.

d)

LinkedList of characters.

52.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int a[] = {1, 2, 3, 4, 5};

    int sum = 0;

    for(int i = 0; i < 5; i++) {

        if(i % 2 == 0) {

            sum += *(a + i);

        }

        else {

            sum -= *(a + i);

        }

    }

    printf("%d", sum);

}

int main() {

        solve();

        return 0;

}

a)

2

b)

15

c)

Syntax Error

d)

3

53.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int first = 10, second = 20;

    int third = first + second;

    {

        int third = second - first;

        printf("%d ", third);

    }

    printf("%d", third);

}

int main() {

        solve();

        return 0;

}

a)

10 30

b)

30 10

c)

10 20

d)

20 10

54.

What is the disadvantage of arrays in C?

a)

The amount of memory to be allocated should be known beforehand.

b)

Elements of an array can be accessed in constant time.

c)

Elements are stored in contiguous memory blocks.

d)

Multiple other data structures can be implemented using arrays.

55.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int a = 3;

    int res = a++ + ++a + a++ + ++a;

    printf("%d", res);

}

int main() {

        solve();

        return 0;

}

a)

12

b)

24

c)

20

d)

18

56.

What will be the value of x in the following code snippet?

#include <stdio.h>

void solve() {

    int x = printf("Hello");

    printf(" %d", x);

}

int main() {

        solve();

        return 0;

}

a)

10

b)

5

c)

1

d)

0

57.

What does the following declaration indicate?

int x: 8;

a)

x stores a value of 8.

b)

x is an 8-bit integer.

c)

Both A and B.

d)

None of the above.

58.

Which of the following is the proper syntax for declaring macros in C?

a)

#define long long ll

b)

#define ll long long

c)

#define ll

d)

#define long long

59.

Which of the following is an exit controlled loop?

a)

While loop.

b)

For loop.

c)

do-while loop.

d)

None of the above.

60.

What is the size of the int data type (in bytes) in C?

a)

4

b)

8

c)

2

d)

1

61.

What will be the output of the following code snippet?

#include <stdio.h>

void swap(int a, int b) {

    int t = *a;

    a = b;

    *b = t;

}

void solve() {

    int a = 3, b = 5;

    swap(&a, &b);

    printf("%d %d", a, b);

}

int main() {

        solve();

        return 0;

}

a)

3 5

b)

5 3

c)

5 5

d)

3 3

62.

How to declare a double-pointer in C?

a)

int *val

b)

int **val

c)

int &val

d)

int *&val

63.

If p is an integer pointer with a value 1000, then what will the value of p + 5 be?

a)

1020

b)

1005

c)

1004

d)

1010

64.

What will be the output of the following code snippet?

#include <stdio.h>

#define VAL 3 * (2 + 6)

void solve() {

    int a = 10 + VAL;

    printf("%d", a);

}

int main() {

        solve();

        return 0;

}

a)

104

b)

24

c)

10

d)

34

65.

Which of the following are not standard header files in C?

a)

stdio.h

b)

stdlib.h

c)

conio.h

d)

None of the above.

66.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    printf("%d %d", (023), (23));

}

int main() {

    solve();

        return 0;

}

a)

023 23

b)

23 23

c)

19 23

d)

23 19

67.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    printf("%d %d %d", (076), (28), (0x87));

}

int main() {

    solve();

        return 0;

}

a)

76 28 87

b)

076 28 0x87

c)

62 28 135

d)

0 0 0

68.

What will be the result of the following code snippet?

#include <stdio.h>

void solve() {

    char ch[10] = "abcdefghij";

    int ans = 0;

    for(int i = 0; i < 10; i++) {

        ans += (ch[i] - 'a');

    }

    printf("%d", ans);

}

int main() {

    solve();

        return 0;

}

a)

45

b)

36

c)

20

d)

100

69.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    bool ok = false;

    printf(ok ? "YES" : "NO");

}

int main() {

    solve();

        return 0;

}

a)

Yes

b)

No

c)

Compilation Error

d)

None of the above

70.

Full form of API

a)

Application Process Interchange

b)

Application Programs Interchange

c)

Application Process Interface

d)

Application Programming Interface

71.

Connector Library to connect MySQL with Python IDLE is

a)

pymysql

b)

mysql.connector

c)

both a and b

d)

none of these

72.

import mysql.connector as mys


mydb = mys.connect( host="localhost", user="root",

password="root"

)


mycursor = mydb.cursor()


mycursor.execute("CREATE DATABASE KVSEC3")

AFTER EXECUTING THE ABOVE CODE. What will be done

(a)  

73.

To display all the databases of MySQL with the help of cursor mycursor , command will be

a)

mycursor.execute("SHOW DATABASES")

b)

mycursor.execute("DESC DATABASES")

c)

mycursor.executes("SHOW DATABASES")

d)

mycursor.execute("SHOW ALL DATABASES")

74.

Correct the error if any

mycursor = mydb.cursor()


mycursor.execute("CREATE TABLE customers (name VARCHAR(25), 'address' VARCHAR(55))")

a)

mycursor.execute('CREATE TABLE customers (name VARCHAR(25), 'address' VARCHAR(55))')

b)

mycursor.execute("CREATE TABLE customers (name VARCHAR(25), address VARCHAR(55))')

c)

mycursor.execute("CREATE TABLE customers (name VARCHAR(25), address VARCHAR(55));")

d)

mycursor.execute("CREATE TABLE customers (name VARCHAR(25), address VARCHAR55))")

75.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed