0% found this document useful (0 votes)
5 views

Programming Logic (1)

Uploaded by

Sunny Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Programming Logic (1)

Uploaded by

Sunny Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Telegram- https://t.

me/placement_0

ls
ia
er
at
m
e
im
pr
T
Q
N

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Some Questions don’t have options since we couldn’t find the options while trying to
get questions from students who have already given TCS Test but anyways we have
put the questions so can atleast give them a shot.

Q.A pointer variable can be 1. Changed within function. 2. Assigned an integer


value. 3. None of these

4. Passed to a function as argument. Correct Op: 4

Q. Which of the following uses structure? 1. Linked Lists


2. Array ofstructures
3. All ofthese

4. Binary Tree Correct Op:3

ls
Q. Strings are character arrays. The last index of it contains the null-
terminated character

ia
1. \t 2. \1 3. \0
er
at
4. \n
Correct Op: 3
m

Q. Which of the following is a collection of different data types? 1. String


e

2. Structure
im

3. Array

4. Files Correct Op:2


pr
T
Q
N

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Q. What function should be used to free the memory allocated by calloc() ? 1.


free();
2. malloc(variable_name,0)
3. dealloc();

4. memalloc(variable_name, 0) Correct Op:1

Q. In the standard library of C programming language, which of the following


header file is designed for basic mathematical operations?

1. conio.h 2. stdio.h 3. math.h 4.Dos.h

Correct Op:3

ls
Q. int **ptr; is?
1. Pointer to integer 2. None ofthese

ia
3. Pointer to pointer 4. Invalid declaration Correct Op: 3

er
Q8. Which of the following special symbol allowed in a variable name? 1.
at
(underscore)
2. -(hyphen)
m

3. |(pipeline)
e

4. * (asterisk) Correct Op:1


im

Q9. All keywords in C are in 1. Uppercase letters


2. None ofthese
pr

3. Lowercaseletters
T

4. Camel Case letters


Q

Correct Op:3
N

Q10. What should the program below print? #include<stdio.h>


#include<string.h>
#include<stdlib.h>

void myfunc(char** param){ ++param;


}
int main(){

char* string = (char*)malloc(64); strcpy(string, "hello_World");


myfunc(&string); myfunc(&string);

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

printf("%s\n", string);
// ignore memory leak for sake of quiz return 0;
}
1. hello_World
2. ello_World
3. lo_World
4. llo_World

Correct Op:1

Q: What is the output of this C code? #include<stdio.h>


voidmain()
{

ls
int k = 5;
int *p =&k;

ia
int **m = &p; printf("%d%d%d\n", k, *p, **p); }
a) 5 5 5
b) 5 5junk
er
at
c) 5 junkjunk
d) Compile timeerror
m

Correct op: D
e

Explanations
1) It would have been 5 5 5 if it were **m and not**p.
im

Q. Which of the following statements about stdout and stderr are true?
pr

a) They both are thesame


T

b) Run time errors are automatically displayed in stderr c) Both areconnected


Q

to the screen bydefault.


d) stdout is line buffered but stderr is unbuffered.
N

Correct Op: D

Explanation -
a) False. b) Not by default. c) Not by default. d) True.

Q: Given the below statements about C programming language:


1) main() function should always be the first function present in a C program
file 2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typcasted to any
type 4) A static variable hold random junk value if it is not initialised

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Which of the above are correct statements? A) 2,3


B) 1,2
C) 1,2,3

D) 1,2,3,4
Correct Op - A
Explanations
In a file you can write a function before main() - False

all the elements of an union share their memory location - True.

A void pointer can hold address of any type and can be typcasted to any type -
True

ls
Static value - False as value is 0

ia
In C, if an object that has static storage duration is not initialized explicitly,

er
then: at
— if it has pointer type, it is initialized to a NULLpointer;
m

— if it has arithmetic type, it is initialized to (positive or unsigned)zero;


e

— if it is an aggregate, every member is initialized (recursively) accordingto


theserules;
im

— if it is a union, the first named member is initialized (recursively)according


pr

to theserules.
T

Q If a function is defined as static, it means


Q

A) The value returned by the function does notchange


N

B) all the variable declared inside the function automatically will beassigned
initial value ofzero

C) It should be called only within the same source code / program file. D)None
of the other choices as it is wrong to add static prefix toa

function Correct Op: C

Access to static functions is restricted to the file where they are declared.
Therefore, when we want to restrict access to functions, we make them static.

Q: Comment on the below while statement=

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

while (0 == 0) { }

A) It has syntax error as there are no statements within braces{}

B) It will runforever

C) It compares 0 with 0 and since they are equal it will exit the loop
immediately D) It has syntax error as the same number is being comparedwith
itself

Correct Op: B
while( 0==0) {} is equivalent to while(1) {}

1. What will happen if in a C program you assign a value to an arrayelement

ls
whose subscript exceeds the size ofarray?

ia
A. The element will be set to0.

er
B. The compiler would report anerror.
C. The program may crash if some important data gets overwritten. D. The
at
array size would appropriatelygrow.
Answer: Option C
m

Explanation:
e

If the index of the array size is exceeded, the program will crash. Hence
"option c" is the correct answer. But the modern compilers will take care of
im

this kind of errors.


pr

2. What does the following declaration mean? int(*ptr)[10];


A. ptr is array of pointers to 10 integers B.ptr is a pointer to an array of 10
T

integers
Q

C.ptr is an array of 10 integers D.ptr is an pointer to array Answer: Option B


N

3. In C, if you pass an array as an argument to a function, what actually gets


passed?

A. Value of elements in array B.First element of the array C.Base address of


the array

D.Address of the last element of array

Answer: Option C

Explanation:

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

The statement 'C' is correct. When we pass an array as a function argument,


the base address of the array will be passed.

4. What will be the output of the program ?#include<stdio.h>


intmain()
{

int a[5] = {5, 1, 15, 20, 25}; int i, j,m;


i =++a[1];
j =a[1]++;

m = a[i++];
printf("%d, %d, %d", i, j, m); return 0;

ls
}

ia
A.2, 1, 15

B.1, 2, 5
er
at
C.3, 2,15
m

D.2, 3,20
e
im

Answer: Option C

Explanation:
pr

Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer
T

array with a size of 5 and it is initiapzed to


Q

a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .


N

Step 2: int i, j, m; The variable i,j,m are declared as an integer type.

Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2

Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.

Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by


1(i++ means 2++ so i=3)

Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m
Hence the output of the program is 3, 2, 15

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

5. Is there any difference int the following declarations? int fun(intarr[]);

int fun(int arr[2]); A.Yes


B.No
Answer: Option B Explanation:

No, both the statements are same. It is the prototype for the function fun() that
accepts one integer array as an parameter and returns an integer value.

6. Are the expressions arr and &arr same for an array of 10 integers?A.Yes
B.No
Answer: Option B

Explanation:

ls
Both mean two different things. arr gives the address of the first int, whereas

ia
the &arr gives the address of array of ints.

er
7. Which of the fplowing statements should be used to obtain a remainder after
at
dividing 3.14 by2.1?
m

A.rem = 3.14 % 2.1;


B.rem = modf(3.14,2.1);
e

C.rem = fmod(3.14,2.1);
D.Remainder cannot be obtain in floating point division. Answer: Option C
im

Explanation:
pr

fmod(x,y) - Calculates x modulo y, the remainder of x/y.


T

This function is the same as the modulus operator. But fmod() performs
Q

floating point divisions.


N

8. What are the types of pnkages? A.Internal and External B.External,Internal


and None C.External andNone

D.Internal
Answer: Option B
Explanation:
External pnkage-> means global, non-static variables and functions. Internal
pnkage-> means static variables and functions with file scope. None pnkage->
means Local variable

9. Which of the fplowing special symbp allowed in a variable name?A.*


(asterisk)

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

B.| (pipepne)
C.-(hyphen)

D._(underscore) Answer: Option D Explanation:

Variable names in C are made up of letters (upper and lower case) and digits.
The underscore character ("_") is also permitted. Names must not begin with a
digit.

Examples of vapd (but not very descriptive) C variable names: => foo
=> Bar
=> BAZ

=> foo_bar => _foo42 => _

ls
=>QuUx

ia
10. Is there any difference between following declarations? 1 : extern intfun();

er
2 : intfun();
A. Both areidentical
at
B. No difference, except extern int fun(); is probably in another file C.intfun();
m

is overrided with extern intfun();


D.None of these
e

Answer: Option B
im

Explanation:
pr

extern int fun(); declaration in C is to indicate the existence of a global


function and it is defined externally to the current module or in another file.
T
Q

int fun(); declaration in C is to indicate the existence of a function inside the


current module or in the same file.
N

Ques. What could be the output for following? main()


{
int a= - - 2;

printf(“%d”,a); }
(A) 2

(B) -2 (C) 1

(D) Error
--2 is incorrect, // Invalid because lvalue is required to

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Ques. Predict the output of following code: main()


{
int i=-1;

-i; //No change in value of i printf(“%d,%d”,i,-i);


}
(A) -1, 1

(B) -1, -1 (C) 1, 1

increment

(D) 0, 1

ls
Ques. Predict the output of following code: main()
{

ia
er
int var=20; // scope of the local variable is within function or block
printf(“%d,”,var); //outer block
at
{
m

int var=30; //Inner block

printf(“%d”,var); }
e
im

(B) 20,30 (C) 20,20 (D) Garbage value Predict the output of following code:
pr

main() {
T

int var=20; // scope of the local variable is within function or block


Q

printf(“%d,”,var); //outer block {


N

(A) Error

int var=30; printf(“%d,”,var);

} printf(“%d”,var); }

//Inner block

//again in outer block

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

(A) Error (B) 20,30,20 (C) 20,20,20 (D) Garbage value

Which among the following operator has the right to left associativity? (A).
Arithmetic
(B). logical

(C). Relational

(D). Increment/Decrement

Note: among logical operators logical NOT has right to left associativity , i.e . !
operator

Predict the output of following code: main()

ls
{

ia
int x,a=10;
x=9*5+7/3-6+a; //45+2-6+10 = 51 printf(“%d”,x);
}
er
at
(A). 51 (B). 51.5 (C). 31 (D). None of these
m

// 7/3 =2 int division


e
im

Predict the output of following code: main()


{
int a=10,x;
pr

x= a-- + ++a;
T

printf(“%d”,x); }
Q
N

(A). 19 (B). 20 (C). 22 (D). 23

Note : For a-- value 10 is used and a is reduced to 9 post decrement


for ++a value 9 is incremented and new value 10 is used preincrement

therefore: x=10+10=20

Predict the output of following code: main()

{
int a=10,x=20;

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

a=a++ + 10; // a = 10+10 first a is increment to 11 but overwritten by 20

x=x+++++a; //x=20+21 aisincrementedfirstfrom

printf(“%d,%d”,a,x); }

(A). 22,43 (B). 12,21 (C). 10,20 (D). 42,42


No option has correct answer.
Correct answer is 21,41

Predict the output of following code: main()

{
int i=10,j=2,k=0,m;

ls
m=++i&&++j&&++k; // m = 11 && 3 && 1 = 1 printf(“%d%d%d%d”,i,j,k,m);
}

ia
er
a. 11,3,1,1 b. 11,2,0,1 c. 11,3,1,0 d. 10,2,0,1
at
Predict the output of following code: main()
m

{
int i=10; printf(“%d,%d”,++i,++i); }
e
im

a. 11,12 b. 12,11 c. 10,11 d. 11,10

Predict the output of following code: main()


pr

{
T
Q

int a,x=(2,3,4,5); //valid statement x = last value in list // x = 5 during declaration


list
N

should be specified inside ( )

a=1,2,3,4,5; // valid; a = 1; first value of the list is assigned to variable

printf(“%d%d”,x,a); }

20to21

a. Error b. 5,1 c. 2,1

d. 5,5

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Predict the output of following code: main()

{
int a,x=2,3,4,5; // Error because list is not within ( ) a=1,2,3,4,5;
printf(“%d%d”,x,a);
}

a. Error b. 5,1 c. 2,1 d. 5,5

Predict the output of following code: main()


{
int x=10,y=-10;

printf(“%x \t”,x<<2); printf(“%x\t”,y>>2); }

ls
// %X hexadeciamal value displayed a.28 fffd b.40 -3

ia
er
c. Error d. 0,1 at
Note : here 16 bit computer is considered.
m

In bitwise operations if number is +ve then simply specied number of bits


shifted in specified direction L or R.
e

If Number is –VE then 2’s complement is used Therefore -10 = 1111 0110 = F5
im

(2’s complement) after 2positions shift → 1111 1101 → FD


pr

in decimal → 1111 1101→10000 0011 → -03


T

Predict the output of following code: main()


Q

{
N

unsigned int a= -1;

signed int b=10;

if(a<b) // if( 10 < 255)

printf(“a is the smallest number”); else


printf(“b is the smallest number”);

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

}
a. a is the smallest number b. b is the smallest number c. Error d. Both
statements

Note: //for unsigned variable negative valued is assigned computer takes


2’complement number to assign.

a = 1111 1111= FF (255)

Predict the output of following code: main()


{

if(1) // True always

printf(“hai”); else

ls
ia
printf(“hello”); }

a. Error c.hello
er
at
b. hai
m

d. No output
e
im

Predict the output of following code: main()

{
pr

}
T

if(5,4,3,2,1,0) // Last value of list is considered printf(“True”);


Q
N

else printf(“False”);

a. True
c. True False

b.False

d.Error

Predict the output of following code: main()

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

a. True b. False

if(5,4,3,2,1,0,8,9) // Last value of list is considered printf(“True”);

else printf(“False”);

c. True False d. Error

Predict the output of following code: main()

ls
if( printf(“Hai”)) // prints content of printf statement and

ia
//takes length of the string for if case its 4, So true
printf(“Face”);
er
at
//execution in this case
m

else printf(“Focus”);
e

}
im

a. Error
c. HaiFocus
pr

b. HaiFace
T
Q

d. Face
N

Predict the output of following code: main()

if( printf(“”)) // prints content of printf statement and //takes length of the string
for if case
case its 1, Sotrue

//execution inthis

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

printf(“Face”); else printf(“Focus”);

a. Error
c. “”Focus

b.Face

d.Face

Predict the output of following code: main()

printf(“Face”); else

ls
printf(“Focus”); }

ia
a. Error
er
at
if(printf(“O”, printf(“Two”))) length of
4, So true
m

/ prints content of printf statement and takes


e

//the string for if case execution in this case its


im

b. OTwoFace
pr

c. HaiFocus d.Face
T

Predict the output of following code: main()


Q

{
N

if(-1) //2’s complement its value FF

printf(“True”); else printf(“False”); }

a. True

c. True False

b. False d. Error

Predict the output of following code: main()

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

{
int a=100,b=300;
if(a>50) // No braces, so only one immediate statement is part of if

a=200; b=400;

printf(“%d”,b); }

a.400

c.100

b. 300 d. Error

ls
Find the error, if any, in the while loop main()

ia
{

er
int i = 1; at
while( i < = 5) {
m

printf(“%d “, i); if ( i < 2)


e

goto here; }
im

}
pr

fun() {
T

here:
Q

printf(“\n I am here”); }
N

Error: _Label → here used in main function but not defined Predict the output
of following code:

main() {

int a=2;

if(a-- , --a, a) // if(2, 0, 0) last value 0 →False

a.

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

c.

printf(“Tom”); else

printf(“Jerry”); }

Tom

Tom Jerry

b.Jerry

d.Error

ls
Predict the output of following code:

ia
main() {

int a=2; switch(a)


er
at
{
m

case 1: printf(“one”);
case 2: printf(“Two”);
e

case 3: printf(“Three”); default:printf(“Invalid option”); }


im

}
pr

a. b. c. d.
T

onetwothree Invalid option one two


Q

None of these
N

Guess the output: main()

// Executable code ; No break statement

printf(“%d”,sizeof('a')); //same as → sizeof(97) }

a. 2 or 4 b. 1 or 3
c. Garbage value d. ASCII value of a

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

NOTE:
// sizeof takes ascii value of character and determines number of bytes
required

by it. Ascii is number, Number is of type int. so integer requires either 2 in 16


or 4 in 32 bit machine

Predict the output of following code: main()

int a=b=c=d=10; // error: ‘b’ , ‘c’, ‘d’ undeclared printf(“%d,%d,%d,%d”,a,b,c,d);

ls
a.

ia
er
NOTE: GV-Garbage Value at
Predict the output of following code: main()
m

{
int b,c,d;
e

int a=b=c=d=10; printf(“%d,%d,%d,%d”,a,b,c,d);


im

}
pr

Error b. 10,10,10,10 c. GV,GV,GV,10 d. GV,GV,GV,GV


T

a.
Q

NOTE: GV-Garbage Value


N

Predict the output of following code: main()

{
int sum;

char ch1='a'; char ch2='b';

Error b. 10,10,10,10 c. GV,GV,GV,10 d. GV,GV,GV,GV

a.

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

c.

sum=ch1+ch2;

printf(“%d”,sum); }

Error 201

// ascii sum; sum = 97+98 = 195

b. 195

d. “ab”

ls
Predict the output of following code: main()

ia
{

er
float a=1.1; at
double b=1.1;
m

if(a==b) // datatype is different cant be compared; hence result will be 0


e

printf(“equal”); else
im

printf(“not equal”);}
pr

a. equal b. notequal
c. Error d. equal not equal
T
Q

What is the output for following? main()


N

{
printf(“%%%%”); }

a. %%%% b. %% c. Error d. Garbage Value

Note:
A `%' is written.

No argument is converted.
The complete conversion specification is`%%'.

so, “%%%%” → prints → %%

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

main()

{ printf(“%d”); }

a. 0 b. 1 c. Garbage value d. Error

Guess the output: main()


{
printf(“\n ks”); printf(“\b mi \a”); printf(“\r ha \n”);

}
a. ksmiha

b. mis

ls
c. hai

ia
er
ks at
d. hamiks
m

Note:
after 1st statement execution:
e

After 2nd : k mi After 3rd : ha i


im

Predict the output of following code: main()


pr

{
T

100; // valid but no effect printf(“%d”,100);


Q

}
N

a. Error b. 100 c. Garbage value d. 100100

Predict the output of following code: main()

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

ls
ia
{ printf(“%d”,printf(“FACE”)); }

a. FACE4 b. Error Note: er


at
//valid
m

c. Garbage value d. FACE


e

First prints content of printf statement


im

Then prints its length in outer printf statement


pr

Predict the output of following code: main()


T

{
Q

printf(“%d”,printf(“FACE”)); //valid
N

printf("",printf("Third "),printf("Second "),printf("First "));

printf("%f%f%f",printf("Third "),printf("Second "),printf("First "));

printf("%d%d%d",printf("Third "),printf("Second "),printf("First "));

Note: Output

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

FACE4

First Second Third

First Second Third 0.000000 0.000000 0.000000

First Second Third 676

Predict the output of following code:


main()
{
printf(“FACE”+2); // valid skip specified number of

//characters from start

ls
}

ia
a. FACE b. FA c. CE d. Garbage value

Predict the output of following code:


er
at
main() {
m

int a=2000; printf(“%2d”,a);


e
im

//format specification

}
pr

a. 2000 b. 20
T

c. 4000 d. Garbage value


Q

Predict the output of following code: main()


N

{
int x,a=10;

x=a==10?printf("hai\t"):printf("hello\n");

printf("%d",x); }

a. hai 4 b. Error c. hello 3 d. hai hello

Note:
First prints content of printf for the case true Then printf its length stored in x

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Predict the output of following code: main()

{
int a=10,b=20,c=5,d;

d=a<b<c; //d=(10<20)<5=1< 5 =1

printf(“%d”,d); }

a.0 b.1 c.5 d.Error


How many of the following are invalid

variable name?

ls
NUMBER _num 93num num93 first.name last name nUMBER midname. 4321

ia
a. 5 b. 3 c. 2 d. More than 5

Predict the output int main()


er
at
{
m

float f=5,g=10;
enum{i=10,j=20,k=50};
e

printf("%d\n",++k);
printf("%f\n",f<<2);
im

printf("%lf\n",f%g);
printf("%lf\n",fmod(f,g)); // function is in math.h return 0;
pr

}
T

Output: Errors
Q

What would the output of this program be? Will there be any error?
N

#define a 10 int main()


{

#define a 50 //Warning is raised for redefining a printf("%d",a); //Prints new


value of a i.e. 50

//k is enumerated constant // f is float


//invalid operands floats

getchar(); //waits for character input

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

return 0; }

Output: 50

Predict the output of below program. int main()


{

char arr[] = "PrepInsta"; printf("%d", sizeof(arr)); getchar();


return 0;

}
Output: 9

Predict the output #include <stdio.h>

ls
int main(void)
{

ia
http://prepinsta.com/ printf("Hello, World !!!\n"); return 0;

}
er
at
Output: Hello, World !!!
m

Predict the output


e

#include <stdio.h> int main(void)


im

int x = printf("PrepInsta"); printf("%d", x);


pr

return 0;
T

}
Q

(A) PrepInsta9 (B) PrepInsta10 (C)PrepInstaPrep (D) PrepInsta1


N

//valid specification http://

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

ls
ia
//first prints message then assigns length its to x

er
Output of following program? #include<stdio.h>
at
int main()
{
m

printf("%d", printf("%d", 1234));


e
im

return 0; }
pr

(A) 12344 (B) 12341 (C) 11234 (D) 41234

Note: First prints inner message 1234


T

then its length in outer printf 4


Q

Hence output : 12344


N

Output of following program? #include<stdio.h>


int main()
{

printf("%d", printf("%d", printf(“%d”,543210)));

return 0; }

(A) 54321061 (B) 543210 (C) 5432101 (D) 5432106

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Note: First prints inner message 543210 then its length in outer printf 6 then its
length in outer printf 1

Hence output : 54321061

Predict the output #include <stdio.h> int main()


{

float c = 5.0;
printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32); return 0;

}
(A) Temperature in Fahrenheit is 41.00 (B) Temperature in Fahrenheit is 37.00
(C) Temperature in Fahrenheit is 0.00 (D) Compiler Error

ls
Note: 9/5 int value → 1*5+32 =37.00 (float)

ia
er
What will be output of the following program?
at
#include<stdio.h> int main(){
m

int a=2,b=7,c=10;
c=a==b; //assign 0 to c printf("%d",c);
e

return 0;
im

}
Output: 0
pr

What will be output of the following program?


T
Q

#include<stdio.h> void main(){


N

int x; x=10,20,30; printf("%d",x); return 0;

}
Output: 10

// Assigns first value to z i.e. 10

What will be output of the following program? #include<stdio.h>

int main(){
int a=0,b=10; if(a=0){

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

printf("true"); }

//value a is 0 hence else case is executed

else{ printf("false");

return 0; }

Output: false int main()

{
signed char i=0; for(; i >= 0; i++)

ls
printf("%d\n", i); getchar();

ia
er
return 0; } at
Output: prints ascii numbers from 0 to 127 What is the output of this C code?
m

#include <stdio.h> void main()


{
e
im

double k = 0;
for (k = 0.0; k < 3.0; k++)
pr

printf("Hello"); }
T

a) Run timeerror
Q

b) Hello is printed thrice


c) Hello is printedtwice
N

d) Hello is printed infinitely

Find the output


# include <stdio.h>

int main() {

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

switch(i) {

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

case 0: i+=5; case 1: i+=2;

case 5: i+=5; default: i+=4; break;

}
printf("%d ", i);

} getchar();

return 0; }

Output : 16 21

//start 0+5+2+5+4 = 16 for first iteration

ls
// i++ in for loop changes i=17 then

ia
Predict the output of following code:
er
at
main()
m

{
int a[20]={1,2,3}; printf(“%d”,sizeof(a));
e
im

default case 17+4=21 ends loop

}
pr

a. 20 b. 6 c. Error d. 40 or80
T

Output: a has 20 memory location of each 2 bytes in case 16 bit m/c 20*2=40bytes
Q

or 20*4=80incase32bitm/c
N

Predict the output of following code: main()

{
int a[]={1,5};

printf("%d,",*a); (*a)++; printf("%d",*a);

//a is base address i.e. a[0] *a its content //content of a[0] is incremented by 1

//new value will be 2

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

a. 1, 5

b. 1, 2 c. Error d. 1,6

Predict the output of following code:

main() {

int a[3]={1,2,3}; printf(“%d”, 2[a]);

}
a. 3 b. 2

// 2[a] → a[2] → *(a+2)

ls
c. Error

ia
er
all are same at
d. 6
m

Predict the output of following code: main()


e

{
printf(“%c”,2[“hai”]); // 2nd character in the string i.e. i
im

}
pr

a. 2 b. h c. Error d. I
T

h→0 a→1 i→2


Q

Predict the output of following code: main()


N

{
char s[]= “”; //null character printf(“%d”,sizeof(s));

}
a. 1 b. Garbage c. Error d. 2

Predict the output of following code: main()

{
int i=0,n;

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

int a[10]={1,2,3,4,5,6,7,8};

n=a[++i]+ i++ + a[i++] + a[i];

printf(“%d”,n); }

a. 7 b. 10 c. 9 d. 8
Output: n = a[1] + 1 + a[2] + a[3] = 2 + 1 + 3 + 4 = 10

Point out the Error : main()


{

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

printf(“%d”,a[1][1]); }

ls
ia
Output: 4

Predict the output of following code: main()


er
at
{
m

int a[3][2]={{1,2},{3,4},{5,6}}; printf(“%d,%d,%d\n”,a[2][1],*(a[2]+1),*(*(a+2)+1));


e

}
im

a. Error b. Garbage value c. 2, 3, 4 d. 6, 6, 6 Output: a[2][1] = 6 *(a[2]+1)= a[2][1]


=6
pr

*(*(a+2)+1) = *(address of row + 1) = content of row 2 col 1 = 6


T
Q

Predict the output of following code: main()


N

{
int arr2D[3][3]={1,2,3,4,5,6};
printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }

a. Error b.1 c.0d.6


Note: base address of the array is compared

Predict the output : main()

{
int a=10,*p;
int *vp;

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

p=&a;
vp=p; printf(“%d”,*p); printf(“%d”,*vp); }

// p→ a // vp → a

both p & vp points to a

b. Error type casting required d. Both are garbage value

a.1010
c. 10 Garbagevalues

Predict the output of following code: main()

ls
{
char a= ‘a’,*p;

ia
er
p=&a; at
printf(“%d,%d”,sizeof(*p) , sizeof(p)); }
m

a.
e

1,2 b.2,2 c.1,1 d.Error


im

Note: sizeof(p) is 2 for 16 bit m/c and 4 for 32 bit m/c Predict the output of
following code:
pr

main() {
T

int a=10,*p; p=&a; printf("%d",*&*p); }


Q

a. 10 b. address of a c. Error d. Address of p Predict the output of following


N

code:

main() {

char *str= “face”,b;

printf(“%d”,-2[str]); // printf ascii value of c with - }

a.-99 b.c c.Error d.b

Predict the output of following code: main()

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

{
int i=10,j=20;

int *p,*q;
*p=i; // only value is assigned to *p q=&j; //pointer initialization printf(“%d,%d”,*p,*q);

}
a. 10, 10 b. 10, 20 c. Error d. Garbage value, 20

char ** array [12][12][12];


Consider array, defined above. Which one of the following definitions and
initializations of p is valid?

1. char ** (* p) [12][12] = array;

ls
2. char ***** p = array;

ia
c. char * (* p) [12][12][12] = array;

er
d. const char ** p [12][12][12] =array; at
Note: array is pointer to pointerarray
( ) has higher priority so *p is pointer to pointer to pointer array
m

What is the difference between int *arr[10]; and int (*arr)[10]; int *arr[10]; //declares
e

array of 10 pointers
im

int (*arr)[10]; // pointer to array 10 intergers ;( ) higher priority


pr

Find the output: void main()


T

{
Q

int i=7; printf("%d",i++*i++); }


N

a. 49 b. 56 c. 64

// 7*8
d. Garbage value

Find the error/output. #include<stdio.h>

int i; // i =0; initialized by default value int kunfu();


int main()
{

while(i) {

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

kunfu();

main(); }

printf("Lovely\n");

return 0; }

int kunfu() {

printf("Pretty");}

//onlyexecutes

ls
a. Lovely b. Pretty c. Lovely Pretty d. Infinite loop

ia
Find the error/output: #include<stdio.h>

int calc(int); int main()


er
at
{
m

int a, b;
a = calc(123);
e

b = calc(123); printf("%d, %d\n", a, b); return 0;


im

int calc(int n) {
pr

int s, d; if(n!=0)
T

{
Q

d = n%10;
n = n/10;
N

s = d+calc(n); }

else
return 0;

a. 6 6

return s; b. 4 4

c. 2 8

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

d. Compilation error

Find out error/output:

f(int p, int q) {

int p;

p = 5;

return p; }

a. 5
b. 0

ls
c. Missing parenthesis in return statement d. Error: re-declaration ofp

ia
Find the error/output: #include <stdio.h>

float sub(float, float); int main()


er
at
{
m

float a = 4.5, b = 3.2, c; c = sub(a, b);


printf("c = %f\n", c); return 0;
e
im

float sub(float a, float b) {


pr

return (a - b); }
T
Q

//function not declared


N

a. 2 b. Compilation error
c. 1.300000 d. Garbage value

Predict the output of following code: struct student

{
int stuid=1234;

char stuname[5]= “abcde”;

}s1; main() {

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

struct student s1;

//invalid can’t initialize members

printf( “%d,%s”,s1.stuid,s1.stuname); }

a. b. c. d.

1234,abcde 12341234 Error abcdeabcde

Predict the output of following code: struct employee

{
int empid;

ls
float empbasic;

ia
}emp1={13}; //valid initialization first value 13 second value set 0 by default
main()
{
er
at
struct employee ;
m

printf( “%d,%f”,emp1.empid,emp1.empbasic);}
e
im

a.

b.
pr

c. d.
T
Q

13, 13
N

13,0.000000

Error
13, garbage value

Point out the error in the following code : main()

{
struct mystruct

{
int a;

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

mystruct b;

mystruct *p; };

a. b. c. d.

// structure must define before use

Error in pointer declaration Error in variable ‘b’ declaration No Error


both a and b

Predict the output of following code: struct student

ls
{

ia
int stuid;

char stuname[5]; }s1={1234,“abcde”};


er
at
main()
m

{
e

struct student s2={5678, “abcde”};


im

if(s1==s2) //invalid comparision struct instances

printf(“true”); else
pr

printf(“false”); }
T
Q

a. true b. false c. Error d. truefalse


N

Predict the output of following code: struct birthdate

{
int date;

int month;

int year; };

main() {

struct student {

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

int stuid;
char stuname[20]; struct birthdate dob;

a.

// sizeof(int)+sizeof(stuname)+sizeof(birthdate) 13 b. 28 c. Error d.7

} s1={1234, “abcde”}; printf(“%d”,sizeof(s1));

Predict the output of following code: union temp

ls
int m1;

ia
char ch; };

main() {
er
at
union temp u1;
m

u1.m1=10;
u1.ch=20; //union uses common memory so recent value is present
e

printf(“%d%d”,u1.m1,u1.ch);
im

}
a. 10, 10 b. 2020 c. Error d. 1020
pr

Predict the output of following code: struct birthdate


T
Q

{
int date;
N

int month;

int year; };

main() {

union student {

int stuid;
char stuname[2]; struct birthdate dob;

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

} u1={1234, “ab”};

printf(“%d”,sizeof(u1)); }

//dob require larger memory hence max size of ul is 6

a. 10 b. 28 c. Error d. 6

Predict the output of following code: struct mystruct

{
int x; // default value of members of structure is 0

int y; };

ls
struct mystruct s1,*pp; main()

ia
{
er
pp=&s1; printf("%d%d\n",(*pp).x,(*pp).y); printf("%d%d\n",pp->x,pp->y);
at
}
m

a. 00 b. Garbage values c. Error d. 11 00


e

Choose the correct option to print out a & b:


im

#include<stdio.h> float a;
double b;
pr

a. printf("%f %lf", a, b) b. printf("%f %Lf", a, b);


T
Q

c. printf("%Lf %f", a, b); d. None


N

Find the output: #include<stdio.h>

int main()
{
float a=2.15529; printf("%2.1f\n", a); return 0;
}

a. 2.15 b. 2.1

//rounds decimal value to next higher digit

c. 2.2 d. Error

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

2) Where the local variables are stored? A. Disk B. Stack C.


Heap D. 13
Select the missing statement? #include<stdio.h> long int
fact(int n); int main() {
\\missing statement }
long int fact(int n) {
if(n>=1)
return n*fact(n-1);
else

ls
return1;

ia
}
Options er
at
A. printf(“%ll\n",fact(5)); B. printf("%u\n",fact(5)); C.
m

printf("%d\n",fact(5)); D. printf("%ld\n",fact(5));
e

Which of the following indicate the end of the file? A. Feof()


im

B. EOF
C. Both feof() andEOF
pr

D. None of thementioned
T

If a function’s return type is not explicitly defined then it’s default to


Q
N

A. int
B. float C. void D.Error

For passing command line argument the main function should be like A.int
main(char *argv[], intargc)
B. int main(intargc)
C. int main(char*argv[])

D. int main( int argc, char*argv[])

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

How many times the below loop will be executed? #include<stdio.h> int main()
{
int i; for(i=0;i<5;i++) {

printf("Hello\n"); } }

Options

A. 5 B. 1

(In C).

C. 0 D. 3

ls
Which of the following is a User-defined data type? A. long int
B. double

ia
C. unsigned longint

D. enum
er
at
Which has the highest precision? A. float
m

B. double
C. unsigned longint
e

D. Long int Floating pointtypes


im

The following table provide the details of standard floating-point types with storage
pr

sizes and value ranges and their precision −


T

Type
Q

float
N

double

long double

Storage size

4 byte

8byte

10 byte

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Value range

1.2E-38 to 3.4E+38

2.3E-308 to 1.7E+308

3.4E-4932 to 1.1E+4932

Precision

6 decimal places

15 decimalplaces

19 decimalplaces

ls
ia
er
at
m
e
im
pr

What will be the output/error?(for input: 6, 9 #include<stdio.h> int fg(int,int);


T

int main()
{
Q
N

int n1,n2,g; scanf("%d%d", &n1,&n2); g=fg(n1,n2); printf("%d",g); }


int fg(int x,int y)

{
while(x!=y) { if(x>y)
return fg(x-y,y); else
return fg(x,y-x); }
return x; }

Options

A. 3
B. 6

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

C. 9
D. Error

How to dynamically release memory? AnsA. With Free Statement


Free()
Truncate()

delete()release()

Ques. What is the function of ftell? Ans. To get the current file Position To getthe
current filename
To get the current file Position

To get the current file attributes To get the current file status

ls
Till Page 46 F

ia
Question 1: Use of an increment statement or decrement statement in C?
Answer:
er
at
There are actually two ways you can do this. One is to use the increment
operator ++ and decrement operator - -. For example, the statement x++ means
m

to increment the value of x by 1. Likewise, the statement x -- means to


decrement the value of x by 1.
e
im

Two types of increments are:


1. pre increment: (increment by 1 then print)and
pr

2. post increment: (print then incremented value will be in buffer). Samething


will be withdecrement.
T
Q

Question 2: In programs we place comment symbols on some codes instead


of deleting it. How does this aid in debugging?
N

Answer:

Placing comment symbols /* */ around a code, also referred to as commenting


out, is a way of isolating some codes that you think maybe causing errors in
the program, without deleting the code.

Question 3: What is the use of a ‘\0' character?


Answer:
This character is used primarily to show the end of a string value.

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Question 4: What is the difference between the = symbol and == symbol?


Answer:

The = symbol is often used in mathematical operations. It is used to assign a


value to a given variable. On the other hand, the == symbol, also known as
equal to or equivalent to, is a relational operator that is used to compare two
values.

Question 5: In C Programming, which of the following operators is incorrect


and why? ( >=, <=, <>, ==)

Answer:

<> is incorrect, all other operators are relational operators. While this operator

ls
is correctly interpreted as not equal to in writing conditional statements, it is
not the proper operator to be used in C programming. Instead, the operator !=

ia
must be used to indicate not equal to condition.

er
Question 6: Can the curly brackets { } be used to enclose a single line of code?
at
Answer:
m

While curly brackets are mainly used to group several lines of codes, it will
still work without error if you used it for a single line. Some programmers
e

prefer this method as a way of organizing codes to make it look clearer,


especially in conditional statements.
im

Question 7: Can I use int data type to store the value 32768? Why/why not?
pr

Answer:
T

No. int data type is capable of storing values from -32768 to 32767. To store
32768, you can use long int instead. You can also use ‘unsigned int, assuming
Q

you don’t intend to store negative values.


N

Question 8: Can two or more operators such as \n and \t be combined in a


single line of program code?

Answer: Yes, it’s perfectly valid to combine operators, especially if the need
arises.

For example: you can have a code like ‘printf (‘Hello\n\n\’World\’)’ to output the
text ‘Hello’ on the first line and ‘World’ enclosed in single quotes to appear on
the next two lines.

Question 9: When is the ‘void’ keyword used in a function? Answer:

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

When declaring functions, you will decide whether that function would be
returning a value or not. If that function will not return a value, such as when
the purpose of a function is to display some outputs on the screen, then void
is to be placed at the leftmost part of the function header. When a return value
is expected after the function execution, the data type of the return value is
placed instead of void.

Question 10: Write a loop statement that will show the following output: 1
12
123

1234 12345 Answer:

for (a=1; a<=5; i++) { for (b=1; b<=a; b++) printf("%d",b); printf("\n");

ls
}

ia
Question 1: How would you round off a value from 1.66 to 2.0?

A. ceil(1.66)
er
at
B. floor(1.66)
C. roundup (1.66) D. Round to(1.66)
m

Answer:A
e

/* Example for ceil() and floor() functions: */ #include<stdio.h>


im

#include<math.h>
int main()
pr

{
T

printf("\n Result : %f" , ceil(1.44) ); printf("\n Result : %f" , ceil(1.66) ); printf("\n


Q

Result : %f" , floor(1.44) ); printf("\n Result : %f" , floor(1.66) ); return 0;


N

}
// Output:
// Result : 2.000000 // Result : 2.000000 // Result : 1.000000 // Result : 1.000000

Question 2: What will be the output of the program? #include<stdio.h>


int X=40;
int main()

{
int X=20;

printf("%d\n", X);

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

return 0; }

A.20

B.40

C.Error

D.No Output

Answer:A

Whenever there is conflict between a local variable and global variable, the
local variable ets priority.

ls
Question 3: A long double can be used if range of a double is not enough to

ia
accommodate a real number.

A. True B. False
er
at
Answer:A
m

True, we can use long double; if double range is not enough. Double = 8 bytes.
Long double = 10 bytes.
e
im

Question 4: A float is 4 bytes wide, whereas a double is 8 bytes wide. A.True


B. False
Answer:A
pr

True,
T

float = 4 bytes. Double = 8 bytes.


Q

Question 5: If the definition of the external variable occurs in the source file
N

before its use in a particular function, then there is no need for an extern
declaration in the function.

A. True
B. False Answer:A

True, when a function is declared inside the source file, that function (local
function) get a priority than the extern function. So there is no need to declare
a function as extern inside the same source file

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Question 6: If the definition of the external variable occurs in the source file
before its use in a particular function, then there is no need for an extern
declaration in the function.

A. True B. False

Answer: A

True, When a function is declared inside the source file, that function(local
function) get a priority than the extern function. So there is no need to declare
a function as extern inside the same source file

Question 7: Size of short integer and long integer can be verified using the
size of() operator.

ls
A. True

ia
er
B. False at
Answer:A
m

True, we can find the size of short integer and long integer using the sizeof()
operator.
e
im

Question 8: Range of double is -1.7e-38 to 1.7e+38 (in 16 bit platform - Turbo C


under DOS)
pr

A. True
B. False
T

Answer:B
Q

False, the range of double is -1.7e-308 to 1.7e+308.


N

Question 9: Size of short integer and long integer would vary from one
platform to another.

A. True
B. False Answer:A

True, Depending on the operating system/compiler/system architecture you


are working on, the range of data types can vary.

Question 10: Range of float id -2.25e-308 to 2.25e+308 A. True


B. False
Answer: Option B

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

False, the range of float is -3.4e-38 to 3.4e+38.

Question 1: What is wrong in this statement? scanf(%d,whatnumber);


Answer:

An ampersand '&' symbol must be placed before the variable name


whatnumber. Placing & means whatever integer value is entered by the user is
stored at the address of the variable name. This is a common mistake for
programmers, often leading to logical errors.

Question 2: What does the format %10.2 mean when included in a printf
statement?

Answer:

ls
This format is used for two things: to set the number of spaces allotted for the

ia
output number and to set the number of decimal places. The number before

er
the decimal point is for the allotted space, in this case it would allot 10 spaces
for the output number. If the number of space occupied by the output number
at
is less than 10, addition space characters will be inserted before the actual
output
m

number. The number after the decimal point sets the number ofdecimal
places, in this case, it’s 2 decimalspaces.
e
im

Question 3: What are linked list?Answer:


pr

A linked list is composed of nodes that are connected with another. In C


programming, linked lists are created using pointers. Using linked lists is one
T

efficient way of utilizing memory for storage.


Q

Question 4: What are binary trees?


N

Answer:

Binary trees are actually an extension of the concept of linked lists. A binary
tree has two pointers, a left one and a right one. Each side can further branch
to form additional nodes, which each node having two pointers as well.

Question 5: Differences between C and Java? Answer:

JAVA is Object-Oriented while C is procedural.


2. Java is an Interpreted language while C is a compiledlanguage.
3. C is a low-level language while JAVA is a high-levellanguage.

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

4. C uses the top-down approach while JAVA uses the bottom-up approach. 5.
Pointer goes backstage in JAVA while C requires explicit handlingof

pointers. Question 6: In header files whether functions are declared or


defined?

Answer: Functions are declared within header file. That is function prototypes
exist in a header file, not function bodies. They are defined in library (lib).

Question 7: What are the different storage classes in C? Answer:

There are four types of storage classes in C. They are extern, register, auto
and static.

ls
Question 8: What does static variable mean? Answer:

ia
Static is an access qualifier. If a variable is declared as static inside a function,

er
the scope is limited to the function, but it will exists for the life time of the
program. Values will be persisted between successive calls to a function.
at
Question 9: How do you print an address? Answer:
m

Use %p in printf to print the address.


e

Question 10: What are macros? What are its advantages and disadvantages?
Answer:
im

Macros are processor directive which will be replaced at compile time.


pr

The disadvantage with macros is that they just replace the code they are not
function calls. Similarly the advantage is they can reduce time for replacing
T

the same values.


Q

Question 1: Difference between pass by reference and pass by value?


N

Answer:

Pass by value just passes the value from caller to calling function so the called
function cannot modify the values in caller function. But Pass by reference will
pass the address to the caller function instead of value if called function
requires to modify any value it can directly modify.

Question 2: What is an object? Answer:

Object is a software bundle of variables and related methods. Objects have


state and behaviour.

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Question 3: What is a class? Answer:

Class is a user-defined data type in C++. It can be created to solve a particular


kind of problem. After creation the user need not know the specifics of the
working of a class.

Question 4: What is the difference between class and structure? Answer:

Structure: Initially (in C) a structure was used to bundle different type of data
types together to perform a particular functionality. But C++ extended the
structure to contain functions also.

The major difference is that all declarations inside a structure are by default
public.

ls
Class: Class is a successor of Structure. By default all the members inside the

ia
class are private.

Question 5: What is pointer? Answer:


er
at
Pointer is a variable in a program is something with a name, the value of which
m

can vary. The way the compiler and linker handles this is that it assigns
e

a specific block of memory within the computer to hold the value of that
variable.
im

Question 6: What is the difference between null and void pointer? Answer:
pr

A Null pointer has the value 0. Void pointer is a generic pointer introduced by
T

ANSI. Generic pointer can hold the address of any data type.
Q

Question 7: what is function overloading? Answer:


N

Function overloading is a feature of C++ that allows us to create multiple


functions with the same name, so long as they have different
parameters.Consider the following function:

int Add(int nX, int nY) {

return nX + nY;

Question 8: what is friend function? Answer:

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

A friend function for a class is used in object-oriented programming to allow


access to public, private, or protected data in the class from the outside.

Normally, a function that is not a member of a class cannot access such


information; neither can an external class. Occasionally, such access will be
advantageous for the programmer. Under these circumstances, the functionor
external class can be declared as a friend of the class using the friend
keyword

Question 9: What do you mean by inline function?

Answer: The idea behind inline functions is to insert the code of a called
function at the point where the function is called. If done carefully, this can
improve the application's performance in exchange for increased compile time

ls
and possibly (but not always) an increase in the size of the generated binary
executables.

ia
er
Question 10: Tell me something about abstract classes? Answer:
at
An abstract class is a class which does not fully represent an object. Instead,
it represents a broad range of different classes of objects. However, this
m

representation extends only to the features that those classes of objects have
in common. Thus, an abstract class provides only a partial description of its
e

objects.
im

Question 1: What is the difference between an array and a list? Answer:


pr

Array is collection of homogeneous elements. List is collection of


heterogeneous elements.
T
Q

For Array memory allocated is static and continuous. For List memory
allocated is dynamic and random.
N

Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.

Array uses direct access of stored members; list uses sequential access for
members.

Question 2: What are the differences between structures and arrays? Answer:

Arrays are a group of similar data types but Structures can be group of
different data types.

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Question 3: What is data structure? Answer:

A data structure is a way of organizing data that considers not only the items
stored, but also their relationship to each other. Advance knowledge aboutthe
relationship between data items allows designing of efficient algorithms for
the manipulation ofdata.

Question 4: Can you list out the areas in which data structures are applied
extensively?

Answer: Compiler Design,

Operating System,
Database Management System, Statistical analysis package, Numerical

ls
Analysis,
Graphics,

ia
er
Question 5: What are the advantages of inheritance? Answer:
at
It permits code reusability. Reusability saves time in program development. It
encourages the reuse of proven and debugged high-quality software, thus
m

reducing problem after a system becomes functional.


e

Question 6: Advantages of a macro over a function? Answer:


im

Macro gets to see the Compilation environment, so it can expand #defines. It is


expanded by the pre-processor.
pr

Question 7: What is command line argument? Answer:


T
Q

Getting the arguments from command prompt in c is known as command line


arguments. In c main function has three arguments. They are:
N

Argument counter Argument vector

Environment vector

Question 8: What are the 4 basics of OOP?


Answer:
Abstraction, Inheritance, Encapsulation, and Polymorphism.

Question 9: Tell how to check whether a linked list is circular.


Answer:
Create two pointers, each set to the start of the list. Update each as follows:

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular\n");
}
}

Question 10: Write a program to swap two numbers without using atemporary
variable.

Answer:
void swap(int &i, int &j) {
i=i+j;

ls
j=i-j; i=i-j; }

ia
er
Ques. 1 Which is the character array used to accept command line arguments?
at
A) charargv
B) char*argv[]
m

C) charargv[]
D) char*argv
e

Ques. 2 What is a dangling


pointer? Points to garbage value
im

Points to a function
Both a and b
pr

None
Ques. 3 Which is not a string function?
T

A) strstr
Q

B)strcmp
C) strupr
N

D) strchr
Ques. 4 Which of the following does not require to include math.h header file?
A) pow()
B) rand()
C)sqrt()
D) sinh()
Ques. 5 What is the task of pre-processor?
A) Expanding

B) Compiling
C) Linking
D) All of theabove

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

Ques. 6 Which of the following is true?


A) realloc() can change the memory size ofarrays
B) Unary operator works on only oneoperand
C) Struct and Union works in sameway.
D) None of theabove
Ques. 7 Which of this is used to skip one iteration:
A) break
B) continue
C) goto
D) return
Ques. 8 Which address does a pointer to an array store:
A) Memory address of the first element of the array Don’t remember the other
options.
Ques. 9 Predict the output:

ls
float a = 0.1;
if(a==0.1)

ia
printf(“Yes”);
else
printf(“No”); Answer would be No.
er
at
Ques. 10 Another output based question which basically displayed the input
string in reverse pattern.
m
For example, ABRACADABRA was displayed as ARBADACARBA.
e
im
pr
T
Q
N

Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0

ls
ia
er
at
m
e
im
pr
T
Q
N

Telegram- https://t.me/placement_0

You might also like