Oracle Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

@chinni: first of all thanks for the reply. I gave the same structure. But this has no way to differentiate which field of the union is used. This is required in the function which will print the record details.

- rising April 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

struct student
{
int ID;
char* Namel
struct {
int rank;
float grade;
}GP;
}

As we know that the initial value of the structure members is 0 so while printing the report we and check if the initial value of rank = 0. If yes then print grade else print rank something like :-

if(student.gp.rank == 0)
printf("%f",student.gp.grade);
else
printf("%d",student.gp.rank);

- dv April 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

typedef union GradeorRank
{
   float grade;
   unsigned int rank ;
} GorR;
typedef struct sturecord{
unsigned int id;
unsigned char a[32];
GorR gr;
} sr;

void test20()
{
	sr a,b;
	a.id=1;
	memcpy(&(a.a),"Tom",sizeof("Tom"));
	a.gr.grade=98.5f;
    b.id=2;
	memcpy(&(b.a),"Jerry",sizeof("Jerry"));
	b.gr.rank=1;

	printf("id %d,name %s,a.gr.rank %d %",a.id,a.a,(int)(a.gr.grade));
	printf("id %d,name %s,a.gr.rank %f %",b.id,b.a,(float)(b.gr.rank));

}

- Anonymous December 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct student
{
int ID;
char* Namel
union{
int rank;
float grade;
}GP;
};

I tink we can define like this..

- Chinni April 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct student
{
int ID;
char* Namel
struct {
int rank;
float grade;
}GP;
}

As we know that the initial value of the structure members is 0 so while printing the report we and check if the initial value of rank = 0. If yes then print grade else print rank something like :-

if(student.gp.rank == 0)
printf("%f",student.gp.grade);
else
printf("%d",student.gp.rank);

- dv April 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use a tagged union for

- aRg May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
using namespace std;
template <class T>
struct node
{
int id;
string name;
T GradeorRank;
public:
node(int id, const string &name, T gr ){
this->id = id;
this->name = name;
GradeorRank = gr;
}

void display();

};
template<class T>
void node<T>::display()
{
cout <<"Student name is:" << name << endl;
cout <<"Student id is :" << id << endl;
cout <<"Garde(Float)/Rank(int) id:" << GradeorRank << endl;
}
int main() {
node <int> st1(120, "st1", 7);
st1.display();
node <float> st2(121, "st2", 86.5);
st2.display();

return 0;
}

- pkg June 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

As size of int and float are different (in most of System).
example: 2 byte for int, 4 byte for float.
the left 16 bit will be 00..00 if it is integer.
else it will have some value for storing float mantesa or exponent part.
using << operator 16 times we can check for all 000 .zeroes .

- manish kevre November 29, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More