Sonoa Systems Interview Question for Testing / Quality Assurances






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

If you do it using this method then it won't give an error ::
#include<iostream>
using namespace std;
int main()
{
int *p,*q;
p=&(*q);
cout<<"p"<<p<<endl;
q=&(*p);
cout<<"q"<<q<<endl;
return 0;
}

but if you do it like this

#include<iostream>
using namespace std;
int main()
{
int *p,*q;
p=&q;
cout<<"p"<<p<<endl;
q=&p;
cout<<"q"<<q<<endl;
return 0;
}

It will give you an error

- Dnyaneshwari December 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

will crash if yo do this. U r trying to drefernece a pointer thts unitialized

- beginner November 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

@P ..
The way you have written it looks incorrect to me. If you write a=&b, as in your case, a has to be a triple pointer as its holding the address of a double pointer b..

- Musheka December 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

@Audrius..
Using void(or generic) pointers was a good idea.I never thought of that.

@Dnyaneshwari
I think even now p & q will hold the same address values.They don't have each other's address values.

- Musheka December 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

no probs ! the only condition is each of the pointers has to be a double pointer.
unsigned long int ** a ;
unsigned long int ** b;
a=&b;
b=&a;
both of the pointers are acting as a self pointer here .
am i wrong somewhere ?
isn't looking right
plz help !

- P December 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Based on the question , I think so there would be a problem having 2 pointers point to each other as to hold the address of the pointer A , Pointer B should be pointer-to-a-pointer and vice versa.

Correct me if Iam wrong..

- Musheka December 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
int *c,*d;
c = &(*d);
d = &(*c);

- Anonymous December 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
int *c,*d;
c = &(*d);
d = &(*c);

- Anonymous December 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Anonymous
By writing the above code you have just made 'c' & 'd' point to the same memory location.They don't point to each others addresses.

Probably I have got the question wrong. Correct me if Iam wrong..

- Musheka December 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// No ptr errors

#include <stdio.h>

int main(int argc, char *argv[])
{
void *A, *B;
A = &B;
B = &A;
printf("*%08x=%08x, *%08x=%08x\n",
(long)A,
*(long*)A,
(long)B,
*(long*)B);

return 0;
}

- Audrius December 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// No ptr errors

#include <stdio.h>

int main(int argc, char *argv[])
{
	void *A, *B;
	A = &B;
	B = &A;
	printf("*%08x=%08x, *%08x=%08x\n",
		(long)A,
		*(long*)A,
		(long)B,
		*(long*)B);
	
	return 0;
}

- Audrius December 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void* a;
	void* b;
	
        b = &a; //b has a's addr
	a = &b; // a has b's addr

- Helper April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

no

- Anonymous December 23, 2009 | Flag Reply


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