Sunday 13 April 2014

UDP Programming for client
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<string.h>
main(int argc,char **argv)
{
int sd,newsd,ret;
socklen_t len;
char buf[20];
struct sockaddr_in cAddr,sAddr;
sd=socket(PF_INET,SOCK_DGRAM,0);
if(sd==-1)
{
perror("socket");
return;
}
sAddr.sin_family=PF_INET;
sAddr.sin_port=htons(atoi(argv[2]));
sAddr.sin_addr.s_addr=inet_addr(argv[1]);
while(1)
{
printf("enter msg:");
scanf("%s",buf);
sendto(sd,buf,strlen(buf),0,(struct sockaddr*)&sAddr,sizeof(sAddr));
printf("connect successful\n");
}
close(sd);
}
UDP Programming for Server
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<string.h>
main(int argc,char **argv)
{
int sd,newsd,ret;
socklen_t len;
char buf[20];
struct sockaddr_in cAddr,sAddr;
sd=socket(PF_INET,SOCK_DGRAM,0);
if(sd==-1)
{
perror("socket");
return;
}
sAddr.sin_family=PF_INET;
sAddr.sin_port=htons(atoi(argv[1]));
sAddr.sin_addr.s_addr=inet_addr("0.0.0.0");
if(bind(sd,(struct sockaddr*)&sAddr,sizeof(sAddr))==-1)
perror("bind");
else
printf("bind sucess\n");
while(1)
{
printf("waiting for message....\n");
bzero(buf,20);
socklen_t y=sizeof(cAddr);
recvfrom(sd,buf,20,0,(struct sockaddr *)&cAddr,&y);
printf("%s %s\n",inet_ntoa(cAddr.sin_addr.s_addr),buf);
}
close(sd);
close(newsd);
}


Read More
TCPIP Client Basic Program
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<string.h>
main(int argc,char **argv)
{
int sd,newsd,ret;
socklen_t len;
char buf[20];
struct sockaddr_in cAddr,sAddr;
sd=socket(PF_INET,SOCK_STREAM,0);
if(sd==-1)
{
perror("socket");
return;
}
sAddr.sin_family=PF_INET;
sAddr.sin_port=htons(atoi(argv[2]));
sAddr.sin_addr.s_addr=inet_addr(argv[1]);
if(connect(sd,(struct sockaddr *)&sAddr,sizeof(sAddr))==-1)
{
perror("connect");
return;
}
printf("connect successful\n");
while(1)
{
printf("enter msg to send...\n");
gets(buf);
ret=send(sd,buf,strlen(buf),0);
if(strcmp(buf,"QUIT")==0)
//exit(0);
break;
if(ret==-1)
{
perror("send");
return;
}
recv(newsd,buf,20,0);
//printf("%s",buf);
if(strcmp(buf,"exit")==0)
exit(0);
}
close(sd);
}

TCPIP Server Basic Program
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<strings.h>
#include<string.h>
main(int argc,char **argv)
{
int sd,newsd;
socklen_t len;
char buf[20];
struct sockaddr_in cAddr,sAddr;
sd=socket(PF_INET,SOCK_STREAM,0);
if(sd==-1)
{
perror("socket");
return;
}
sAddr.sin_family=PF_INET;
sAddr.sin_port=htons(atoi(argv[1]));
sAddr.sin_addr.s_addr=inet_addr("0.0.0.0");
if(bind(sd,(struct sockaddr *)&sAddr,sizeof(sAddr))==-1)
{
perror("bind");
return;
}
printf("bind successful....\n");
listen(sd,5);
len=sizeof(cAddr);
printf("waiting for client request...\n");
newsd=accept(sd,(struct sockaddr *)&cAddr,&len);
if(newsd==-1)
{
perror("accept");
return;
}
printf("connection accepted\n");
while(1)
{
printf("waiting for data...\n");
bzero(buf,20);
recv(newsd,buf,20,0);
if(strcmp(buf,"QUIT")==0)
break;
printf("received: %s\n",buf);
}
close(sd);
close(newsd);
}

Read More

Wednesday 9 April 2014

Synfosys Model Paper

1>Given a number x, less than 100. How will you generate true with probability x/100. So if x = 65, how will you generate true with probability 65/100. You can represent true by 1 and false by 0.
 
SOL:     void foo(  )
               {
                   int X=65,NUM;
                   NUM=rand( )%100 + 1;
                   if(NUM<=X)
                     printf("true");
                  else
                     printf("false");
           }
2> Given 50 red pens and 50 blue pens, two jars(A,B) initially empty. These 100 pens are to be distributed b/w the jars such that the probability of picking a red pen is maximum.

 SOL: We need to add the probability of finding a red pen in one jar and add it to the probability of finding it in the other. So the probability would b: 0.5x0.5 (probability of picking Jar A)x(probability of picking red pen in that jar) + 0.5x0.5(probability of picking Jar b)x(probability of picking red pen in that jar) = 0.5 But there exists a distribution in which the probability of picking one color pen can be increased and i.e. put 1 red pen in jar A and other 49 red and 50 blue in jar B. This gives us the probability of picking red pen as 0.5x1 (probability of picking Jar A)x(probability of picking red pen in that jar) + 0.5x(49/99) (probability of picking Jar b)x(probability of picking red pen in that jar) = .7474 ANS
1> void main()
    {
   int i=320;
   char *ptr=(char *)&i;
   printf("%d",*ptr);
}                       ANS-64
2>#define x 5+2
  void main()
  {
    int i;
    i=x*x*x;
    printf("%d",i); ANS 27
}

3>void main(){
char c=125;
    c=c+10;
    printf("%d",c);  ANS -121
}
4>void main(){
   float a=5.2;
  if(a==5.2)
     printf("Equal");
  else if(a<5.2)
     printf("Less than");
  else
     printf("Greater than");  ANS- less than
}
5>void main(){
  int i=4,x;
  x=++i + ++i + ++i;
  printf("%d",x);       ans-in gcc-18 in turbo c-21
}
6>  void main(){
 int a=2;
 if(a==2){
   a=~a+2<<1;
   printf("%d",a);   ans-compiler error
 }
 else{
  break;
 }
}
7>void main(){
  int a=10;
  printf("%d %d %d",a,a++,++a);ans-12,11,11
}
8>void main(){
   char *str="Hello world";
   printf("%d",printf("%s",str)); ans-hello world11
}
9>void main(){
   char *str=NULL;
   strcpy(str,"cquestionbank");  ans-turbo c-(null)i.e null ptr assignment
   printf("%s",str);                 gcc-runtime error
}
10>void main(){
  int i=0;
  for(;i<=2;)
   printf(" %d",++i); ans 1,2,3
}

 
1> Explain the memory representation of int a=7;
ANS:        if binary num is in form-    ABCD          00000000|00000000|00000000|00000111
         then  memory representation is -CDBA          00000000|00000111|00000000|00000000                                     
                                                    
2>Explain floating point representation of real numbers:?
sol:
      float num: 1.46    by IEEE STD: sign bit:      1
                                      expo bit:       8
                                     significant bit:23
     bias value:127 
         try urself
3>find the size of function?
 sol: there is no predefined operator or any library function to calculate the size of any userdefined function:we can calculate size of fn by finding the size of each variables encountered in that function; example:
         void foo()
         {
           int arr[20];
            int x=10;
            int *ptr=&x;
}                             ANS>>   SIZE= sizeof(arr)+ sizeof(x)+sizeof(ptr);
4>convert integer to string??
  main()
{ 
 int num=6;
  char buf[10];
 sprintf(buf,"%d",num);
 printf("%s",num);
}
5>compare two strings which are present in different memory location??
 void cmp(char *str,char *ptr)
{
  if(strcmp(str,ptr)==0)
    printf("equal")
else 
    printf("not equal");
}

1>REVERSE THE NUMBER USING POINTER ex inp-109012 o/p 210901?
  
SOL: int rev(int *num)          main()
                                 { int num=12345;
                              pf("%d",rev(&num));
                                  }
      {
       int r,sum=0;
         while(*num)
         {
            r=*num%10;
            sum=sum*10 + r;
           *num/=10;
       }
         return sum;
}
2>string uppercase to lowercase and vice versa?
sol:main()
   {
    char str[100],buff[100],ch;
     int i,j,k=0;
   printf("enter str:");
    gets(str);
      for(i=0;str[i];i++)
       {
            ch=str[i];
            if(ch>='A'&&ch<='Z')
            buff[k]=ch+32;
            else if(ch>='a'&& ch<='z')
             buff[k]=ch-32;
              k++;
      }
          puts(buff);
}
3>find the location of substring in a given string:if string is "synfosyssolution" and sub string is "sol" :then output will b 9 ?
main()
{
char  str[]="synfosyssolution";
char sub[]="sol";
int i,j,cnt=0;
for(i=0;str[i];i++)
{
  if(str[i]==sub[0])
   {
     for(j=1;sub[j];j++)
      {
        if(str[i+j]!=sub[j])
         {
           break;
         }
      }
   }
     if(sub[j]!='\0')
      cnt++;
}
printf("sub str found at pos :%d\n",cnt+1);
}
5>Reverse word of a sentence??if input is "synfosys business soln ltd" than output will be "ltd soln business synfosys"??
       void xrev(char *,char *)
sol:   main()
       {
          char str[]="synfosys business soln ltd";
           char *ptr=0,*x=0,*y=0;
          for(ptr=str;*ptr;ptr++);//move ptr to last
            xrev(ptr-1,str)
            x=str-1;
            
            y=str;
      while(x++<ptr)
        {
       if(*x=='0'||*x==' ')
        {
            xrev(y,x-1)
            y=x+1;
         }
}
void rev(char *l,char *r)
{
 char t;
while(l<r)
{
t=*l;
*l++=*r;
*r--=t;
}
}
Read More

C Programming Important Links

Read More

TerraData Interview Experience, Bangalore

Hi, everyone this is one of my friend interview experience in TerraData. i am happy to say that i got placed in Teradata. I will discuss my Experience of Teradata paper pattern for Embedded Systems

INTERVIEW DETAILS
I had total  of  7 rounds and they asked me about Data Structures ,C,Linux and than Networking finally about my project.
1)In first round at tera data we had written test which had one question from string operation and heap sort
3)Second round was my technical interview.
    In this round they asked me every thing about only sorting techniques , sheduling algarithm  and IPC and about my project
4)Third round was technical interview and communication skills and also your coding skills.
5)Fourth round was HR round .Here she asked me about my self introduction  also about my strengths and weakness ,she spoke about bond and place of working . She tested my comfort level which means they will ask you when will you report.
6)In fifth round i had a telephonic interview from US .
   In this round he asked me self introduction,what are all the subjects i know , my domain interest ,my eager  and my comfort  level only basics of technical.
   In this round emphasis is more given to communication 
7)Sixth round was just medical  checkup and meeting the manager to know about my domain and submitting the documents.

IMPORTANT QUESTIONS
All the below listed questions i was not able to answer.
1)What is multithreading.
Ans: a technique by which a single set of code can be used by several processors at different stages of execution.

2)What is parallel programming.
Ans:Parallel computing is a form of computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently. ...

3)Explain the counting seamaphore algarithms.
4)How many total sorting techniques are there and what are all they explain in detail.
Ans: already Mentioned above.
5)reaserch your own algarithem  for sorting  the given  random array .(Should not use bubble sort,heap sort,merge sort,quick sort .It should be your own)
6)What will be the result of int *p=malloc(0); (malloc of zero).


7)Without using the shmat how to get the shared memory.
Read More
Hello Friends,

this is something about SAFRAN recruiting process...

for the written test 

there would be two sections of C & APTITUDE.

After this there would be 2 rounds of Technical panel.

Which mainly focuses on C.
In C ...
you should know the depths of pointer & Arrays,structure,functions.

they will also ask topics other than C (like UNIX etc.) to understand how you are involved in your learning...

also some puzzles will be involved in their questionnaires...

After all this there will be a dedicated HR round.
in Which they test your confidence and Communication skills...

All the Best.....
Read More
hii friends,

In a process of selecting into siemens the following rounds will be conducted as a part of Recruitment. written test, Technical Interview and HR Interview.. it may be helpful for you people who are waiting for getting into job

written test:
The written test consists of 2 sections
1) Technical 2) Aptitude
In written test (Technical) majority of the questions which will be on C,C++, that too they concentrate much on theoritical concepts than programming questions.. the questions are not that much easy, but the concepts discussed in class rooms are enough to clear the written test.. In aptitude section the questions are not that much difficult, and the questions are mainly based on Time and work, ages, Time and distance, ratios, ages..
    guys I strongly recommend you to please go through aptitude because any company written test you people will find aptitude section for sure.. so please spend some time for aptitude.. some of my friends who are very strong in programming and technicals have not qualified in written exam due to sectional cut off..

Technical Interview:

My Technical Interview was conducted abot 40 minutes.. In my technical interview I was mainly asked about C programming questions which I mentioned in my resume.. programs like largest among array of numbers(easy).. they also concentrated on pointers and some concepts related to data structures.. some puzzles were asked and some some questions like "what is the angle between hours hand and minute hand at 3:15.." ans is 7.5 deg.. which I have done before interviewer.. and some questions are asked on my project and mini project.. so guys please be prepared with ur project which you have done in ur b.tech along with C,C++,linux,tcp-ip...

HR Interview:

My HR Interview was conducted abot 30 min... My HR Interview was a combination of HR round and managerial round.. many questions were asked in hr interview.. like tell brief introduction about yourself, questions on my paper presentations which I presented in my b.tech, about my project, some puzzles, reasoning questions. some general questions were asked like "If you are present in that situation what will you do at that time".. the total interview was done based on the things which I've mentioned in my resume...

    Friends I wish you all the very best who are preparing for the further interviews..
Read More

Interview Questions in VVDN Technologies, Chennai

Interview Process: 
First -Written test was about aptitude, basic electronics & C programming
second - Two Interviews was mostly focused on digital & analog electronics, C programming and basics questions on all embedded topics.
  
Interview Experience:
Two questions on c-programming 
1. Optimized code for multiplications of two numbers without using multiplication operator.
int xor, and, temp;
and = x & y;
xor = x ^ y; 

while(and != 0 )
{
 and <<= 1; 
 temp = xor ^ and;
 and &= xor; 
 xor = temp; 
}

Or
#include <stdio.h>

unsigned int add(unsigned int x, unsigned int y)
{
        unsigned int xor, and, temp;
        and = x & y;
        xor = x ^ y;
        while(and != 0 ) {
                and <<= 1;
                temp = xor ^ and;
                and &= xor;
                xor = temp;
        }
        return xor;
}

int main()
{
        unsigned int multiplicand = 41,
                     multiplier = 6,
                     res = 0;

        while(multiplier != 0) {
                if (multiplier & 1) {
                        res = add(res, multiplicand);
                }
                multiplier >>= 1;
                multiplicand <<= 1;
        }
        printf("6 times 41 equals %u\n", res);
        return 0;
}
2. Optimized code for expressing a number(n) in binary one's  and displaying it's equivalent in  integer. ( Example: if n = 4, then binary ones's[1111] and the integer equivalent is 15) 

3. More conceptual questions on basic (digital & analog) electronics and logical questions. (Example: Design a circuit when an input and output signals are provided using logic gates with propagation delay )

4. Implementations of logic gates using transistors & diodes. And filters using RLC components. 

Diode Logic Gates:
5. Questions on OP-AMP

Please do feel free to reach me out, if you have any questions regarding the interview and I wish you all best for you placements.

Read More
Hi fellowVectorians...!
               Firstly i HaveBeen Thanking My Parents For Supporting me and Thankful to Director Raju Sir for providing Genuine Placements. and Guru Sir for Exploring The Knowledge On Technical and Lcs Kishore,Tandava RamaKrishna,Sangu Gurung for explaing patiently for what  I Asked...
      I Had Ateended For 6 Companies..
    1) CUPOLA Technologies
          As I Attended in middle Of My Course I dont have Sufficient knowledge to answer Questions Regarding 8051 Micro Controller..
         Written Test 1:   Basic Questions On C,Linux,Tcp/ip 
          Written Test 2: C Programming and TCP/IP Client Server Communication PRogram
           Technical Round : 
 a)Questions On Answers We Written in 1st Round and 2nd Round
 b)Questions  on My B.tech Project In Depth (I am not Able To Explain Well) 
 c)Questions On MicroController Very Depth

2)VVDN Chennai
       Yep,I Dont Have Enough Knowlege To Clear The Written Test Bcz it Contains Electronics....
       remaining Sections C Basics And Apti are very Easy.... 
3) TeraData
        VeryGood Company , Having 7 Rounds in it Selection process and HighPackage around 4.8 Lakh 
              They Are mainly concentrated on Data Structers And Sorting Mechanisms
       I Got Question from Linked list and tree Concepts In Round1
            in 2nd round they focused on Hashmap,Binary Tree and Programs On Strings
             I am Back From This Round......
4)EliteCore
      I Faced 6 Rounds for this company..
      They Are Mainly Focusing on Apti , Puzzles and Programming 
    Wrtitten Test 1: C basics,Apti
    Written Test 2:  Data Structres Programming,Linux Internals
    Technical Round 1 : C Basics ,C programming ,Puzzles
     Technical Round 2: Linux Internals, Tcp/Ip ,Vector Project
    Techinical Round 3: questions from Toatl Vector Course Cirriculam and Answers Which are Written by Us...
     Telephonic Round : itself Mixing Of Technical and HR questions..(I Rejected)
5)Safran Engineering Services,BLR
    i had faced written test and Technical only 
  In Techinical I got Questions From C very Depth
  --> Create Generis Stack which has Able to add Integer or charcter or string or float pr even Structure also..
--> Create Cirular Stack
Ans:
I have a need for a fixed-size (selectable at run-time when creating it, not compile-time) circular buffer which can hold objects of any type and it needs to be very high performance. I don't think there will be resource contention issues since, although it's in a multi-tasking embedded environment, it's a co-operative one so the tasks themselves can manage that.
My initial thought were to store a simple struct in the buffer which would contain the type (simple enum/define) and a void pointer to the payload but I want this to be as fast as possible so I'm open to suggestions that involve bypassing the heap.
Actually I'm happy to bypass any of the standard library for raw speed - from what I've seen of the code, it's not heavily optimized for the CPU : it looks like they just compiled C code for things like strcpy()and such, there's no hand-coded assembly.
Any code or ideas would be greatly appreciated. The operations required are:
  • create a buffer with specific size.
  • put at the tail.
  • get from the head.
  • return the count.
  • delete a buffer.
Program:
typedef struct circular_buffer
{
    void *buffer;     // data buffer
    void *buffer_end; // end of data buffer
    size_t capacity;  // maximum number of items in the buffer
    size_t count;     // number of items in the buffer
    size_t sz;        // size of each item in the buffer
    void *head;       // pointer to head
    void *tail;       // pointer to tail
} circular_buffer;

void cb_init(circular_buffer *cb, size_t capacity, size_t sz)
{
    cb->buffer = malloc(capacity * sz);
    if(cb->buffer == NULL)
        // handle error
    cb->buffer_end = (char *)cb->buffer + capacity * sz;
    cb->capacity = capacity;
    cb->count = 0;
    cb->sz = sz;
    cb->head = cb->buffer;
    cb->tail = cb->buffer;
}

void cb_free(circular_buffer *cb)
{
    free(cb->buffer);
    // clear out other fields too, just to be safe
}

void cb_push_back(circular_buffer *cb, const void *item)
{
    if(cb->count == cb->capacity)
        // handle error
    memcpy(cb->head, item, cb->sz);
    cb->head = (char*)cb->head + cb->sz;
    if(cb->head == cb->buffer_end)
        cb->head = cb->buffer;
    cb->count++;
}

void cb_pop_front(circular_buffer *cb, void *item)
{
    if(cb->count == 0)
        // handle error
    memcpy(item, cb->tail, cb->sz);
    cb->tail = (char*)cb->tail + cb->sz;
    if(cb->tail == cb->buffer_end)
        cb->tail = cb->buffer;
    cb->count--;
}

--> Function Pointers
function pointer (or subroutine pointer or procedure pointer) is a type of pointer supported by third-generation programming languages (such as PL/ICOBOLFortran,dBASE dBL, and C) and object-oriented programming languages (such as C++ and D). Instead of referring to data values, a function pointer points to executable code within memory. When dereferenced, a function pointer can be used to invoke the function it points to and pass it arguments just like a normal function call. Such an invocation is also known as an "indirect" call, because the function is being invoked indirectly through a variable instead of directly through a fixed name or address. Function pointers can be used to simplify code by providing a simple way to select a function to execute based on run-time values.

Wild Pointer,Dangling Pointer
Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations.
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, a silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults (UNIX, Linux) orgeneral protection faults (Windows). If the overwritten data is bookkeeping data used by the system's memory allocator, the corruption can cause system instabilities.
Wild pointers arise when a pointer is used prior to initialization to some known state, which is possible in some programming languages. They show the same erratic behaviour as dangling pointers, though they are less likely to stay undetected.
-->  Structure Padding , Holes ,Pragma pack ,find size of structure without using sizeof OPerator
--> Valgrind Tool to find out Memory Leaks
6)American MegaTrends  Inc
 I got Selected In This Company..
 Process:
Written Test 1: Apti,IQ questions(Objective),C questions(Objective),Java Questions(Objective),HR Questions(Descriptive) ,Two Java Progrms
Written Test 2: C and C++ Programming And Theotical Questions
HR Round : Asked me about from myself from my  childhood  to till now.. about 1 Hour...

    Finally I Got Selected in Ami..
Read More