vijaymukilan
BAN USERquestion its mentioned that it should not be from head.
its not possible to traverse the single link list from tail.
Yes there is no best here. Then there is no need for implementing other synchronization mechanism. So we need to understand the application.
If a common memory is shared then we can say shared memory is good idea.
Again if i need to indicate a message or signal then there is no need for shared memory to stored that message or signal.
if its send a buffer from one thread to another i can use pipeing. ...
TCP= transport layer=4
IP = network layer =3 my answer is it works in the last 4 layers.
A set of API used for communicating between two system. It runs in the kernel space.
- vijaymukilan July 18, 2013local variable are stored in stack. The stack is a common space used by all function for its manipulation once its control move out the values are pop out.
- vijaymukilan July 17, 2013it wont be accurate in case we declar two local variable because compiler may try to optimize the code, so the behavior of local variable is undefined.
so just call a function & check as said by - Punch
doubt its MS question.....Simply i don't belive it...
- vijaymukilan July 17, 2013int i=6,j=4,k=3,Max;
Max= i*(i>j&& i>k)+j*(j>i &&j> k)+k *(k>i&&k>j);
Do i miss , any special case??
It will return garbage value may be hello there is in garbage...
we need to make static to return always hello there
#include<stdio.h>
#include<string.h>
char *xyz()
{
static char str[32];
strcpy(str,"Hello there!");
return(str);
}
void main()
{
printf("%s",xyz());
}
answer is 0 ,
the var in other files are not wrong since static var will be created in all files with its own file scope, its allowed in C.
void * Myalloc ( int size )
{
// lets assume we get the address of the available memory in a;
// n be the available size
void *f =a // now f is the void pointer which points to the available memory )
if( size > N )
printf(" in sufficient memory ");
else
n=n+size ;// size is reduced from availabe n
return f;
}
so it will always give a valid address
Correct me if i am wrong
just wondering f is lost here... but seems to be correct
- vijaymukilan July 17, 2013class PoweredDevice
{
public:
PoweredDevice(int nPower)
{
cout << "PoweredDevice: " << nPower << endl;
}
};
class Scanner: virtual public PoweredDevice
{
public:
Scanner(int nScanner, int nPower)
: PoweredDevice(nPower)
{
cout << "Scanner: " << nScanner << endl;
}
};
class Printer: virtual public PoweredDevice
{
public:
Printer(int nPrinter, int nPower)
: PoweredDevice(nPower)
{
cout << "Printer: " << nPrinter << endl;
}
};
class Copier: public Scanner, public Printer
{
public:
Copier(int nScanner, int nPrinter, int nPower)
: Scanner(nScanner, nPower), Printer(nPrinter, nPower), PoweredDevice(nPower)
{
}
};
int main()
{
Copier cCopier(1, 2, 3);
}
here the virtual make sure that powerdevice is call by copier only once..
note:thanks alex @learncpp
sizeof is unary operator;
- vijaymukilan July 17, 2013To keep the argument going.. if you write a C program in C++ compiler, its again a C program ...
So we just need to talk about a C++ program and a C program. There is no doubt C will be faster as C++ use dynamic polymorphism which will slow..
well done !!
- vijaymukilan July 16, 2013Char *ptr1= malloc(sizeof(5));
Char *ptr2= malloc(sizeof(6));
ptr1=ptr2;
free (ptr1); /* now it frees the ptr2 allocation */
here the 5 allocated is memory leak which can be freed as we dont have the pointer of that memory location.
Just curious why you have used both Semaphore & mutex ??
- vijaymukilan July 10, 2013Only in case of round robing - Waiting first will be executed
In priority based - 1 which has higher priority will execute
/* finding duplicate using hash table */
- vijaymukilan August 17, 2013int find_duplicate(node **head)
{
node *result=*head;
int return_val=0;
int hashtable[50]={NULL}; /* table has to be modified based on the data range */
node *slow=*head;
node *fast=*head;
fast=fast->link->link;
while (fast != slow ) /* assumed the given link list is circular */
{
fast=fast->link->link;
if(hashtable[slow->data]==0)
hashtable[slow->data]=true;
else if(hashtable[slow->data] >= 1)
{
return return_val=1; /* found duplicate */
} /* objective was just to print true incase duplicate found */
slow=slow->link;
}
if(fast==slow) /* its used to find the start of the circle */
{ /* when the slow reaches the circle, the fast would also
do a roatation so we can make sure that we check for duplicate */
slow=*head;
while (slow != fast)
{
slow=slow->link;
fast=fast->link;
if(hashtable[fast->data]==0)
hashtable[fast->data]=true;
else if(hashtable[fast->data] >= 1)
{
return return_val=1; /* found duplicate */
}
}
return 0; /* no duplicate */ /* it also means that we traversed the entire link list now */
}
}