Showing posts with label c interview questions. Show all posts
Showing posts with label c interview questions. Show all posts

ordinary variable and pointer in C

What is the difference between ordinary variable and pointer in C?
A An ordinary variable is like a container it can hold any value and we can change the value of ordinary variable at a time throughout the program .A pointer is a variable that stores the address of another Variable.

far and near pointers in c

What is "far" and "near" pointers in "c" ?
A:“Near" and "far" pointers are actually non-standard qualifiers that you'll find only on x86 systems. They reflect the odd segmentation architecture of Intel processors. In short, a near pointer is an offset only,which refers to an address in a known segment. A far pointer is a compound value, containing both a segment number and an offset into that segment. Segmentation still exists on Intel processors, but it is not used in any of the mainstream 32-bit operating systems developed for them, so you'll generally only find the "near" and "far" keywords in source code developed for Windows 3.x,MS-DOS, Xenix/80286, etc.

Segment and offset addresses difference

Q:What are segment and offset addresses?
A: When paging technique is performed, the page will breaks into segments and its sequence is said to be segments and its width can be said as offset. In short,segment is a physical address and offset is logical address.

Element inserted in an array list?

Where can an element are inserted in an array list?
Insertion into an array list is possible in two ways:

  • Insertion at the beginning.
  • Insertion at the end.
  • Insertion in between.

Searching in array list carried out?

How is searching in an array list carried out?
For searching an element in an array list, first we traverse the array list and with traversing, we compare each element of array with the given element.

Operations performed on C++ lists?

What are the operations performed on C++ lists?
The operations that can be performed on lists are insertion, deletion, traversal and search.

Bitwise Operators Interview Questions

 Bitwise Operators Interview Questions
1.In which numbering system can the binary number 1011011111000101 be easily converted to?
a)Decimal system
b)Hexadecimal system
c)Octal system
 d)No need to convert
Answer: Option B
Explanation:
Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.
2.Which bitwise operator is suitable for turning off a particular bit in a number?
 a)&& operator
b)& operator
c)|| operator
d)! operator
Answer: Option B
3.Which bitwise operator is suitable for turning on a particular bit in a number?
a)&& operator
b)& operator
c)|| operator
d)! operator

 Answer: Option D
4.Which bitwise operator is suitable for checking whether a particular bit is on or off?
a)&& operator
b)& operator
c)|| operator
d)! operator
Answer: Option B
5.Left shifting a number by 1 is always equivalent to multiplying it by 2?
a)True
b)False
Answer: Option A
Explanation:
0001 => 1
0010 => 2
0100 => 4
1000 => 8

Can structures be assigned to variables and passed to and from functions?

Can structures be assigned to variables and passed to and from functions?
Yes, they can!
But note that when structures are passed, returned or assigned, the copying is done only at one level (The data pointed to by any pointer fields is not copied!.

Do Global variables start out as zero?

Do Global variables start out as zero?
Un initialized variables declared with the "static" keyword are initialized to zero. Such variables are implicitly initialized to the null pointer if they are pointers, and to 0.0F if they are floating point numbers.
Local variables start out containing garbage, unless they are explicitly initialized.
Memory obtained with malloc() and realloc() is likely to contain junk, and must be initialized. Memory obtained with calloc() is all-bits-0, but this is not necessarily useful for pointer or floating-point values (This is in contrast to Global pointers and Global floating point numbers, which start as zeroes of the right type).

C Bit fields Interview Questions

C Bit fields Interview Questions
1)Write a C program to count bits set in an integer?
2)What purpose do the bitwise and, or, xor and the shift operators serve?
3)How to reverse the bits in an integer?
4)Check if the 20th bit of a 32 bit integer is on or off?
5)How to reverse the odd bits of an integer?
6)How would you count the number of bits set in a floating point number?

C Pointers Interview Questions

C Pointer Interview Questions
1)What does *p++ do? Does it increment p or the value pointed by p?
2)What is a NULL pointer? How is it different from an unitialized pointer? How is a NULL pointer defined?
3)What is a null pointer assignment error?
4)Does an array always get converted to a pointer? What is the difference between arr and &arr? How does one declare a pointer to an entire array?
5)Is the cast to malloc() required at all?
6)What does malloc() , calloc(), realloc(), free() do? What are the common problems with malloc()? Is there a way to find out how much memory a pointer was allocated?
7)What's the difference between const char *p, char * const p and const char * const p?
8)What is a void pointer? Why can't we perform arithmetic on a void * pointer?
9)What do Segmentation fault, access violation, core dump and Bus error mean?
10)What is the difference between an array of pointers and a pointer to an array?
11)What is a memory leak?
12)What are brk() and sbrk() used for? How are they different from malloc()?
13)What is a dangling pointer? What are reference counters with respect to pointers?
14)What do pointers contain?
15)Is *(*(p+i)+j) is equivalent to p[i][j]? Is num[i] == i[num] == *(num + i) == *(i + num)?
16)What operations are valid on pointers? When does one get the Illegal use of pointer in function error?
17)What are near, far and huge pointers?
18)What is the difference between malloc() and calloc()?
19)Why is sizeof() an operator and not a function?
20)What is an opaque pointer?
21)What are the common causes of pointer bugs?

Teradata C Interview Questions

Teradata C Interview Questions
1.What is select?
2.What is poll?
3.How do you create thread?
4.Which library you link with when you use pthreads?
5.How do you create process?
6.How many times fork() returns? What are the values?
7.What is the difference between fork() and exec() system calls?
10.Do you know readers writer problem?
11.Take a data structure and synchronization mechanism and solve (write code for) the readers writer (in fact they asked for multiple writers)?
12.Why did you use while instead of if when checking for the full/empty condition (in solution to the readers writer problem)?
13.What are the differences between a process and a thread?
14.What are the things that thread doesn’t share with process?
15.Why there is separate stack for each thread?
16.What is fopen?
17.What is the difference between fopen and open?
18.What is the difference between high level functions and low level functions?
19.What open returns?
20.Descriptors returns by the open will be in sequence? Justify?
21.Why open doesn’t return 0 or 1 or 2?
22.How do you find size of a file?
23.What is fstat?
24.What are different options available with cc
25.What an output files contains?

Order of Evaluation in C CPP Interview Questions

Order of Evaluation in C CPP Interview Questions
1.Under my compiler, the code “int i = 7; printf(“%d\n”, i++ * i++);”
prints 49. Regardless of the order of evaluation, shouldn’t it
print 56?

A:The operations implied by the postincrement and postdecrement
operators ++ and — are performed at some time after the operand’s
former values are yielded and before the end of the expression, but
not necessarily immediately after, or before other parts of the
expression are evaluated.

2.But what about the &&, ||, and comma operators?
A:There is a special exception for those operators, (as well as ?: );
left-to-right evaluation is guaranteed.

c faqs on pointers

C faqs on pointers

1)What are pointers really good for, anyway?
2)I'm trying to declare a pointer and allocate some space for it, but it's not working. What's wrong with this code?
char *p;
*p = malloc(10);
3)Does *p++ increment p, or what it points to?
4)I'm trying to use pointers to manipulate an array of ints. What's wrong with this code?
int array[5], i, *ip;
for(i = 0; i < 5; i++) array[i] = i;
ip = array;
printf("%d\n", *(ip + 3 * sizeof(int)));
I expected the last line to print 3, but it printed garbage.
5)I have a char * pointer that happens to point to some ints, and I want to step it over them. Why doesn't  ((int *)p)++;  work?
6)Why can't I perform arithmetic on a void * pointer?
7)I've got some code that's trying to unpack external structures, but it's crashing with a message about an ``unaligned access.'' What does this mean?
8)I have a function which accepts, and is supposed to initialize, a pointer:
void f(int *ip)
{
static int dummy = 5;
ip = &dummy;
}
But when I call it like this:
int *ip;
f(ip);
the pointer in the caller remains unchanged.
9)Suppose I want to write a function that takes a generic pointer as an argument and I want to simulate passing it by reference. Can I give the formal parameter type void **, and do something like this?
void f(void **);
double *dp;
f((void **)&dp);
10)I have a function extern int f(int *);
which accepts a pointer to an int. How can I pass a constant by reference? A call like

f(&5);
doesn't seem to work.
11)Does C even have ``pass by reference''?
12)I've seen different syntax used for calling functions via pointers. What's the story?
13)What's the total generic pointer type? My compiler complained when I tried to stuff function pointers into a void *.
14)How are integers converted to and from pointers? Can I temporarily stuff an integer into a pointer, or vice versa?
15)How do I convert an int to a char *? I tried a cast, but it's not working.
16)What's wrong with this declaration?
char* p1, p2;
I get errors when I try to use p2.
17)What are ``near'' and ``far'' pointers?
keywords:
c interview questions
c++ faq
faq on pointers in c
faq on arrays in c
faq videos
c tutorial
faqs on strings in c
steve summit
faq on pointers in c
faq on arrays in c
c++ faq
programming in c textbook
c tutorial
c programming resources
c language reference
cinterviews.com
use of pointers in c
pointer in c example
pointers in c pdf
use of pointers in c++
types of pointers in c
pointers in c geeks for geeks
double pointers in c
what is pointer in c
advantages of pointers in c
pointers to manipulate an array of ints
arithmetic operations on void pointers
void pointer function
void pointer in c++
pointer arithmetic
cast void pointer to int
void*' is not a pointer-to-object type
how to print void pointer value in c
generic pointer in c
(void *) in c
convert pointer to integer c++
how to convert pointer into integer
int to pointer cast warning
integer to pointer casting
c++ get pointer as integer
conversion from pointer to smaller integer
how to convert char pointer to integer in c
uintptr_t

c interview answers

C interview answers

C interview question1: What is atexit() ?
Answer:Function atexit( ) recevies parameter as the address of function of the type void fun ( void ). The function whose address is passed to atexit( ) gets called before the termination of program. If atexit( ) is called for more than one function then the functions are called in "first in last out" order. You can verify that from the output.


#include
void fun1( )

{

printf("Inside fun1\n");

}

void fun2( )

{

printf("Inside fun2\n");

}

main( )

{

atexit ( fun1 ) ;

/* some code */
atexit ( fun2 ) ;
printf ( "This is the last statement of
program?\n" );
}

C interview question2 How do I write a user-defined function, which deletes each character in a string str1, which matches any character in string str2?
Answer: The function is as shown below:

Compress ( char str1[], char str2[] )
{
int i, j, k ;
for ( i = k = 0 ; str1[i] != ‘\0’ ; i++ )
{
for ( j = 0 ; str2[j] != ‘\0’ && str2[j] !=
str1[i] ; j++ );
if ( str2[j] == ‘\0’ )
str1[k++] = str1[I] ;
}
str1[k] = ‘\0’
}

C interview question3:How does free( ) know how many bytes to free?
Answer: The malloc( ) / free( ) implementation remembers the size of each block allocated and returned, so it is not necessary to remind it of the size when freeing.

C interview question4:What is the use of randomize( ) and srand( ) function?
Answer: While generating random numbers in a program, sometimes we require to control the series of numbers that random number generator creates. The process of assigning the random number generators starting number is called seeding the generator. The randomize( ) and srand( ) functions are used to seed the random number generators. The randomize( ) function uses PC's clock to produce a random seed, whereas the srand( ) function allows us to specify the random number generator's starting value.

C interview question5:How do I determine amount of memory currently available for allocating?
Answer: We can use function coreleft( ) to get the amount of memory available for allocation. However, this function does not give an exact amount of unused memory. If, we are using a small memory model, coreleft( ) returns the amount of unused memory between the top of the heap and stack. If we are using a larger model, this function returns the amount of memory between the highest allocated memory and the end of conventional memory. The function returns amount of memory in terms of bytes.

C interview question6:How does a C program come to know about command line arguments?
Answer: When we execute our C program, operating system loads the program into memory. In case of DOS, it first loads 256 bytes into memory, called program segment prefix. This contains file tables,environment segment, and command line information. When we compile the C program the compiler inserts additional code that parses the command, assigning it to the argv array, making the arguments easily accessible within our C program.

C interview question7:When we open a file, how does functions like fread( )/fwrite( ), etc. get to know from where to read or to write the data?
Answer: When we open a file for read/write operation using function like fopen( ), it returns a pointer to the structure of type FILE. This structure stores the file pointer called position pointer, which keeps track of current location within the file. On opening file for read/write operation, the file pointer is set to the start of the file. Each time we read/write a character, the position pointer advances one character. If we read one line of text at a step from the file, then file pointer advances to the start of the next line. If the file is opened in append mode, the file pointer is placed at the very end of the file. Using fseek( ) function we can set the file pointer to some other place within the file.

Keywords:

c interview questions
c++ faq
faq on pointers in c
faq on arrays in c
faq videos
c tutorial
faqs on strings in c
steve summit
faq on pointers in c
faq on arrays in c
c++ faq
programming in c textbook
c tutorial
c programming resources
c language reference