Select chapter



functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c interview questions and answers

1
How to access a structure member in C?
  1. to access a structure element, we have to always use "." operator
  2. to access a structure element, we have to always use "." operator if we are using normal variables, and we have to use "->" operator if we are using structure pointer variable.
  3. to access a structure element, we have to always use "." operator if we are using structure pointer variables, and we have to use "->" operator if we are using normal structure variable.
  4. to access a structure element, we have to always use "->" operator
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
5
To store 
1. marital status married/ unmarried
2. gender male/female 
which of the below structures suits best?
  1. struct EmpStatus{
     char m_stats, gender;
    };
  2. struct EmpStatus{
     int m_stats, gender;
    };
  3. struct EmpStatus{
     unsigned m_stats:2;
     unsigned gender:2;
    };
  4. struct EmpStatus{
     unsigned m_stats:1;
     unsigned gender:1;
    };
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
7
In the below question , what does printf("%p %p", s1.cname, s2.cname); will print ?

#include  <stdio.h>

struct company{
    int cno;
    char *cname;
} s1, s2;

int main(void)
{
    s1.cname = malloc(100);
    s1.cno = 1;
    strcpy(s1.cname, "skill gun");
    
    s2 = s1;
    printf("%d %s ", s2.cno, s2.cname);
    
    return 0;
}
  1. it prints the address of "skill gun" allocated in the heap. the address of s1.cname and s2.cname will be same.
  2. it prints "skill gun" two times.
  3. it prints the address of "skill gun" allocated in the heap. the address of s1.cname and s2.cname will be different.
  4. none of the above.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
12
which of the below statements are true about structure copying and array copying?
  1. we can copy values of one array to other array using "=" operator.
  2. we can copy values of one variable to other variable of same structure using "=" operator.
  3. both option1 & 2 are correct.
  4. all are incorrect
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
19
Example for accessing structure members in c:
Which of the below codes are wrong way to access structure variables?
  1. struct company{
        int cno;
        char *cname;
    } s1, s2;
    
    int main(void)
    {
    
        s1.cname = malloc(100);
        s1.cno = 1;
        strcpy(s1.cname, "skill gun");
        
        struct company *p = &s1;
        printf("%d %s", (*p).cno, (*p).cname);
        return 0;
    }
  2. #include  <stdio.h>
    
    struct company{
        int cno;
        char *cname;
    } s1, s2;
    
    int main(void)
    {
    
        s1.cname = malloc(100);
        s1.cno = 1;
        strcpy(s1.cname, "skill gun");
        
        struct company *p = &s1;
        printf("%d %s", *p.cno, *p.cname);
        return 0;
    }
  3. #include  <stdio.h>
    
    struct company{
        int cno;
        char *cname;
    } s1, s2;
    
    int main(void)
    {
    
        s1.cname = malloc(100);
        s1.cno = 1;
        strcpy(s1.cname, "skill gun");
        
        struct company *p = &s1;
        printf("%d %s", p->cno, p->cname);
        return 0;
    }
  4. #include  <stdio.h>
    
    struct company{
        int cno;
        char *cname;
    } s1, s2;
    
    int main(void)
    {
    
        s1.cname = malloc(100);
        s1.cno = 1;
        strcpy(s1.cname, "skill gun");
        
        struct company *p = &s1;
        printf("%d %s", s1.cno, s1.cname);
        return 0;
    }
Show Answer
Share Facebook gmail Twitter
20
Assume that I want to store some data degrees(int), salary(float). But I know that at any given point of time I will either store degree or salary, but not both. then which of the below data structures I have to use?
  1. struct DS{
    int degree;
    float salary;
    };
  2. union DS{
    int degree;
    float salary;
    };
  3. we can use any of the option 1 and 2.
  4. we have to use by mixing both option 1 and 2.
Show Answer
Share Facebook gmail Twitter
Read more papers :