Programming Logic (1)
Programming Logic (1)
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.
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
2. Structure
im
3. Array
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
3. Lowercaseletters
T
Correct Op:3
N
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
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
Correct Op: D
Explanation -
a) False. b) Not by default. c) Not by default. d) True.
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
D) 1,2,3,4
Correct Op - A
Explanations
In a file you can write a function before main() - False
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
to theserules.
T
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
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.
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
while (0 == 0) { }
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) {}
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
integers
Q
Answer: Option C
Explanation:
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
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
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
C.rem = fmod(3.14,2.1);
D.Remainder cannot be obtain in floating point division. Answer: Option C
im
Explanation:
pr
This function is the same as the modulus operator. But fmod() performs
Q
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
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
B.| (pipepne)
C.-(hyphen)
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
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
Answer: Option B
im
Explanation:
pr
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
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
printf(“%d”,var); }
e
im
(B) 20,30 (C) 20,20 (D) Garbage value Predict the output of following code:
pr
main() {
T
(A) Error
} printf(“%d”,var); }
//Inner block
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
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
x= a-- + ++a;
T
printf(“%d”,x); }
Q
N
therefore: x=10+10=20
{
int a=10,x=20;
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
printf(“%d,%d”,a,x); }
{
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
{
T
Q
printf(“%d%d”,x,a); }
20to21
d. 5,5
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
{
int a,x=2,3,4,5; // Error because list is not within ( ) a=1,2,3,4,5;
printf(“%d%d”,x,a);
}
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
If Number is –VE then 2’s complement is used Therefore -10 = 1111 0110 = F5
im
{
N
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
printf(“hai”); else
ls
ia
printf(“hello”); }
a. Error c.hello
er
at
b. hai
m
d. No output
e
im
{
pr
}
T
else printf(“False”);
a. True
c. True False
b.False
d.Error
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
a. True b. False
else printf(“False”);
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
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
a. Error
c. “”Focus
b.Face
d.Face
printf(“Face”); else
ls
printf(“Focus”); }
ia
a. Error
er
at
if(printf(“O”, printf(“Two”))) length of
4, So true
m
b. OTwoFace
pr
c. HaiFocus d.Face
T
{
N
a. True
c. True False
b. False d. Error
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
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;
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() {
case 1: printf(“one”);
case 2: printf(“Two”);
e
}
pr
a. b. c. d.
T
None of these
N
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
ls
a.
ia
er
NOTE: GV-Garbage Value at
Predict the output of following code: main()
m
{
int b,c,d;
e
}
pr
a.
Q
{
int sum;
a.
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
c.
sum=ch1+ch2;
printf(“%d”,sum); }
Error 201
b. 195
d. “ab”
ls
Predict the output of following code: main()
ia
{
er
float a=1.1; at
double b=1.1;
m
printf(“equal”); else
im
printf(“not equal”);}
pr
a. equal b. notequal
c. Error d. equal not equal
T
Q
{
printf(“%%%%”); }
Note:
A `%' is written.
No argument is converted.
The complete conversion specification is`%%'.
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
main()
{ printf(“%d”); }
}
a. ksmiha
b. mis
ls
c. hai
ia
er
ks at
d. hamiks
m
Note:
after 1st statement execution:
e
{
T
}
N
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
ls
ia
{ printf(“%d”,printf(“FACE”)); }
{
Q
printf(“%d”,printf(“FACE”)); //valid
N
Note: Output
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
FACE4
ls
}
ia
a. FACE b. FA c. CE d. Garbage value
//format specification
}
pr
a. 2000 b. 20
T
{
int x,a=10;
x=a==10?printf("hai\t"):printf("hello\n");
printf("%d",x); }
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
{
int a=10,b=20,c=5,d;
d=a<b<c; //d=(10<20)<5=1< 5 =1
printf(“%d”,d); }
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
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
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
return 0; }
Output: 50
}
Output: 9
ls
int main(void)
{
ia
http://prepinsta.com/ printf("Hello, World !!!\n"); return 0;
}
er
at
Output: Hello, World !!!
m
return 0;
T
}
Q
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
return 0; }
pr
return 0; }
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
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
}
Output: 10
int main(){
int a=0,b=10; if(a=0){
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
printf("true"); }
else{ printf("false");
return 0; }
{
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
double k = 0;
for (k = 0.0; k < 3.0; k++)
pr
printf("Hello"); }
T
a) Run timeerror
Q
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
}
printf("%d ", i);
} getchar();
return 0; }
Output : 16 21
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
}
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
{
int a[]={1,5};
//a is base address i.e. a[0] *a its content //content of a[0] is incremented by 1
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
a. 1, 5
b. 1, 2 c. Error d. 1,6
main() {
}
a. 3 b. 2
ls
c. Error
ia
er
all are same at
d. 6
m
{
printf(“%c”,2[“hai”]); // 2nd character in the string i.e. i
im
}
pr
a. 2 b. h c. Error d. I
T
{
char s[]= “”; //null character printf(“%d”,sizeof(s));
}
a. 1 b. Garbage c. Error d. 2
{
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};
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
int a[][]={{1,2},{3,4},{5,6}};
printf(“%d”,a[1][1]); }
ls
ia
Output: 4
}
im
{
int arr2D[3][3]={1,2,3,4,5,6};
printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }
{
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
a.1010
c. 10 Garbagevalues
ls
{
char a= ‘a’,*p;
ia
er
p=&a; at
printf(“%d,%d”,sizeof(*p) , sizeof(p)); }
m
a.
e
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
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
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
{
Q
a. 49 b. 56 c. 64
// 7*8
d. Garbage value
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 a, b;
a = calc(123);
e
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
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>
return (a - b); }
T
Q
a. 2 b. Compilation error
c. 1.300000 d. Garbage value
{
int stuid=1234;
}s1; main() {
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
printf( “%d,%s”,s1.stuid,s1.stuname); }
a. b. c. d.
{
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
{
struct mystruct
{
int a;
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
mystruct b;
mystruct *p; };
a. b. c. d.
ls
{
ia
int stuid;
{
e
printf(“true”); else
pr
printf(“false”); }
T
Q
{
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.
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
{
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)); }
a. 10 b. 28 c. Error d. 6
{
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
#include<stdio.h> float a;
double b;
pr
int main()
{
float a=2.15529; printf("%2.1f\n", a); return 0;
}
a. 2.15 b. 2.1
c. 2.2 d. Error
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
B. EOF
C. Both feof() andEOF
pr
D. None of thementioned
T
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[])
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
The following table provide the details of standard floating-point types with storage
pr
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
int main()
{
Q
N
{
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
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
Answer:
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
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
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.
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
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
#include<math.h>
int main()
pr
{
T
}
// Output:
// Result : 2.000000 // Result : 2.000000 // Result : 1.000000 // Result : 1.000000
{
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
True,
T
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
A. True
B. False
T
Answer:B
Q
Question 9: Size of short integer and long integer would vary from one
platform to another.
A. True
B. False Answer:A
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
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.
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
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).
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
Question 10: What are macros? What are its advantages and disadvantages?
Answer:
im
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
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.
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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.
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
return nX + nY;
Telegram- https://t.me/placement_0
Telegram- https://t.me/placement_0
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
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
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?
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
Environment vector
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
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
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