CSC Interview Questions
- 0of 0 votes
Answers`#include<stdio.h>
- ajaybhardwaj789 May 22, 2014 in India
int main(void)
{
int s[4][2] = { {1234,56}, {1212,33}, {1434,80}, {1312,78} };
int (*p)[2];
int i, j, *pint;
for( i=0; i<=3; i++)
{
p = &s[i];
pint = (int*)p; //Q. My Question is why we are required to type cast here. ?
printf("\n");
for( j=0; j<=1; j++)
{
printf("%d",*(pint+j));
}
}
return 0;
}`
Why we are required to perform the typecasting at the comment line ?
What is the exact difference between
1. Pointer to an array int (*ptr)[10]; and
2. Array of pointers int *ptr[10];| Report Duplicate | Flag | PURGE
CSC Software Engineer / Developer C - 0of 0 votes
AnswersThis was at a recent written test...
There is a toycar placed on a 5 by 5 board.We can give 5 commands to it ,
PLACE(X,Y,F) where x denotes X Axis,y denotes Y Axis and F denotes the direction to which its facing.
MOVE->Move will move the toycar one step in the direction where its facing
LEFT->Left will turn the toycar by 90 degrees to its left and face it to the new direction .Note:Left will not move the toycar, it will just change the direction
RIGHT->Right will turn the toycar by 90 degrees to its right and face it to the new direction .Note:Right will not move the toycar, it will just change the direction
REPORT->Report shall tell me the X Axis,YAxis and Direction of the toycar. like 0,0,NORTH
Note:You cannot move,left,right,report the toycar unless you place it.
Assume its a Prod level code, Solve it in Java only.
Below is my code and I haven't been selected, please tell me if there is better way to do it because my solution is correct but probably very basic.Thanks.
- Anonymous December 03, 2012 in Indiapackage com.ds; public class ToyCar { private ToyCar toycar; private boolean isToyPlaced; private int xAxis,yAxis; private enum Direction {EAST,WEST,NORTH,SOUTH}; private Direction direction; public int getxAxis() { return xAxis; } public void setxAxis(int xAxis) { this.xAxis = xAxis; } public int getyAxis() { return yAxis; } public void setyAxis(int yAxis) { this.yAxis = yAxis; } public Direction getDirection() { return direction; } public void setDirection(Direction direction) { this.direction = direction; } ToyCar(){ } public ToyCar(int xAxis,int yAxis,Direction direction) { this.xAxis=xAxis; this.yAxis=yAxis; this.direction=direction; } public void place(int x,int y, Direction d){ if(x<0||x>5||y<0||y>5 || d==null){ System.out.println("Place Error:Attempt to place toy outside the box"); return; } toycar = new ToyCar(x, y, d); isToyPlaced=true; } public void move(){ if(!isToyPlaced){ System.out.println("Move Error:Attempt to Move Toy without placing in board"); return; } if(toycar.getDirection().equals(Direction.EAST)){ int newPosition=toycar.getxAxis()+1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setxAxis(newPosition); }else if(toycar.getDirection().equals(Direction.WEST)){ int newPosition=toycar.getxAxis()-1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setxAxis(newPosition); }else if(toycar.getDirection().equals(Direction.NORTH)){ int newPosition=toycar.getyAxis()+1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setyAxis(newPosition); }else if(toycar.getDirection().equals(Direction.SOUTH)){ int newPosition=toycar.getyAxis()-1; if(newPosition<0||newPosition>5){ System.out.println("Move Error:Attempt to place toy outside the box"); return; } toycar.setyAxis(newPosition); } } public void left(){ if(!isToyPlaced){ System.out.println("Left Error:Attempt to Move Toy without placing in board"); } if(toycar.getDirection().equals(Direction.EAST)){ toycar.setDirection(Direction.NORTH); } else if(toycar.getDirection().equals(Direction.WEST)){ toycar.setDirection(Direction.SOUTH); } else if(toycar.getDirection().equals(Direction.NORTH)){ toycar.setDirection(Direction.WEST); } else if(toycar.getDirection().equals(Direction.SOUTH)){ toycar.setDirection(Direction.EAST); } } public void right(){ if(!isToyPlaced){ System.out.println("Right Error:Attempt to Move Toy without placing in board"); } if(toycar.getDirection().equals(Direction.EAST)){ toycar.setDirection(Direction.SOUTH); } else if(toycar.getDirection().equals(Direction.WEST)){ toycar.setDirection(Direction.NORTH); } else if(toycar.getDirection().equals(Direction.NORTH)){ toycar.setDirection(Direction.EAST); } else if(toycar.getDirection().equals(Direction.SOUTH)){ toycar.setDirection(Direction.WEST); } } public void report(){ if(!isToyPlaced){ System.out.println("Report Error:How can i report when I am not on board"); return ; } System.out.println(toycar.getxAxis()+" , "+toycar.getyAxis()+" , "+toycar.getDirection()); } public static void main(String[] args){ ToyCar to = new ToyCar(); to.place(0, 0, Direction.WEST); to.left(); to.move(); to.report(); } }
| Report Duplicate | Flag | PURGE
CSC Java Developer Java - 0of 0 votes
AnswerWhat is the base complexity of inserting an item in Binary tree?
- Sudha260983 October 10, 2012 in India| Report Duplicate | Flag | PURGE
CSC Software Analyst - 0of 0 votes
AnswersWhat is the base complexity of searching an item in
- Sudha260983 October 10, 2012 in India
a)Selection sort algorithm
b)Linked list
c)BInary Tree
d) Hash table
e) Queue| Report Duplicate | Flag | PURGE
CSC Software Analyst Data Structures