TCS Placement Questions & Answers :: TCS
481 / 652
A calculator has a key for squaring and one for inverting. So if x is the displayed number, then pressing the square key will replace x by x2 and pressing the invert key will replace x by 1/x. If initially the number displayed is 6 and one alternately presses the invert and square key 16 times each, then the final number displayed (assuming no roundoff or overflow errors) will be
A(6^(-2))^16
B(6^(2))^16
C6^32
D632
Answer: Option B
Explanation:Even number of inverse key has no effect on the number.
For example, Initially the given number is 6. Square key makes it 6^2 and invert key makes it 1/6^2. Now again square key makes it (1/6^2)^2=1/6^4 and invert key makes it 6^4.
Now observe clearly, after pressing square key 2 times, the power of 6 became 4.
By pressing the square key, the value got increased like 2, 4, 8, .... Which are in the format of 2^n.
So after the 16 pressings the power becomes 2^16
So the final number will be (6^2)^16=6^65536
Submit Your Solution
482 / 652
#include <stdio.h>
int main()
{
static int i;
int j;
for(j=0;j<10;j++)
{
i= i+2;
i = i-j;
}
printf("%d",i);
return 0;
}
A25
B-25
C20
D-20
ENone of these
Answer: Option B
Explanation:Here is no explanation for this answer
Submit Your Solution
483 / 652
#include <stdio.h>
int main()
{
int ones, twos, threes, others;
int c;
ones = twos = threes = others = 0;
while ((c = getchar ()) != EOF)
{
switch (c)
{
case '1': ++ones;
case '2': ++twos;
case '3': ++threes;
break;
default: ++others;
break;
}
}
printf ("%d %d", ones, others);
return 0;
}
A1 1
B3 4
C3 2
D3 3
EError
Answer: Option D
Explanation:Here is no explanation for this answer
Submit Your Solution
484 / 652
#include <stdio.h>
void print(char *p);
int main()
{
char s[] = "T.C.S", *A;
print(s);
return 0;
}
void print(char *p)
{
while (*p != '\0')
{
if (*p != '.')
printf ("%c", *p);
p++;
}
}
ATCS
BT.C.S
CSegmentation fault
DNone of the above
Answer: Option A
Explanation:Here is no explanation for this answer
Submit Your Solution
485 / 652
Which of the choices is true for the mentioned declaration?
const char *p;
and
char * const p;
Choose one of them:
AYou can't change the character in both
BIn first case, you can't change the character and second case you can’t change the pointer
CYou can't change the pointer in both
DIn first case you can't change the pointer and in second case you can't change the character
ENone of these
Answer: Option B
Explanation:Here is no explanation for this answer
ShortCut By :: sudhanIn C programming language, *p represents the value stored in a pointer and p represents the address of the value, is referred as a pointer. const char* and char const* says that the pointer can point to a constant char and value of char pointed by this pointer cannot be changed.
const char *ptr : This is a pointer to a constant character. You cannot change the value pointed by ptr, but you can change the pointer itself. “const char *” is a (non-const) pointer to a const char.
char *const ptr : This is a constant pointer to non-constant character. You cannot change the pointer p, but can change the value pointed by ptr.
Submit Your Solution
Tags: TCS Accenture Amazon Capgemini Cognizant Goldman Sachs IBM L&T Infotech Happiest Minds Wipro Tech Mahindra
486 / 652
#include<stdio.h>
int main(){
char p[]="String";
int x;
if(p=="String"){
printf("Pass 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
else{
printf("Fail 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
return 0;
}
APass 1 Pass 2
BFail 1 Fail 2
CPass 1 Fail 2
DFail 1 Pass 2
ESyntax error during compilation
Answer: Option D
Explanation:Here is no explanation for this answer
Submit Your Solution
487 / 652
#include<stdio.h>
#include<malloc.h>
int myalloc(char *x, int n){
x= (char *)malloc(n*sizeof(char));
memset(x,\0,n*sizeof(char));
}
int main(){
char *g="String";
myalloc(g,20);
printf("The string is %s",g);
return 0;
}
ARun time error/Core dump
BThe string is: String
CThe string is: Oldstring
DSyntax error during compilation
ENone of these
Answer: Option B
Explanation:Here is no explanation for this answer
Submit Your Solution
488 / 652
#include<stdio.h>
#include<string.h>
char *gxxx(){
static char xxx[1024];
return xxx;
}
int main(){
char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is : %s",gxxx());
return 0;
}
AThe string is: string
BThe string is: Oldstring
CRun time error/Core dump
DSyntax error during compilation
ENone of these
Answer: Option B
Explanation:Here is no explanation for this answer
Submit Your Solution
489 / 652
#include<stdio.h>
int main(){
unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
printf("%u %d",x,y);
return 0;
}
Asame, and x=MAXINT, y=-1
Bnot same, and x= MAXINT, y= -MAXINT
Csame , and x=MAXUNIT,y -1
Dsame, iand x=y=MAXUNIT
Enot same, and x=MAXINT, y=MAXUNIT
Answer: Option A
Explanation:Here is no explanation for this answer
Submit Your Solution
490 / 652
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main(){
int i;
char a[]="String";
char *p="New Sring";
char *Temp;
Temp=a;
a=malloc(strlen(p) + 1);
strcpy(a,p); //Line no:9//
p = malloc(strlen(Temp) + 1);
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
return 0;
}
Chose correct option
ASwap contents of p and a and print
BGenerate compilation error in line number 8
CGenerate compilation error in line number 5
DGenerate compilation error in line number 7
EGenerate compilation error in line number 1
Answer: Option B
Explanation:Here is no explanation for this answer
Submit Your Solution
Here is the list of questions asked in TCS Aptitude Test Question with Answers page 49. Practice TCS Written Test Papers with Solutions and take Q4Interview TCS Online Test Questions to crack TCS written round test. Overall the level of the TCS Online Assessment Test is moderate. Only those candidates who clear the written exam will qualify for the next round, so practic all the questions here and take all the free tests before going for final selection process of TCS