0% found this document useful (0 votes)
37 views

C Pointers

Pointers in C allow variables to store memory addresses and reference values at those addresses. Pointers enable call by reference by passing the address of a variable rather than its value. Function pointers allow a variable to store the address of a function, so that function can be called using the pointer variable. Generic or void pointers can point to data of any type, but require casting before dereferencing.

Uploaded by

kushagratrivedi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

C Pointers

Pointers in C allow variables to store memory addresses and reference values at those addresses. Pointers enable call by reference by passing the address of a variable rather than its value. Function pointers allow a variable to store the address of a function, so that function can be called using the pointer variable. Generic or void pointers can point to data of any type, but require casting before dereferencing.

Uploaded by

kushagratrivedi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pointers in c questions for interview

In this article I will be posting some good c pointer interview questions answers. Pointers in C are special type of variables that are used to point the value of particular data type by storing address of that particular data type. Pointers in c play role in call by reference when we want any change in formal parameter to get reflected in actual parameters. In this post you can find somebasic pointer questions in c.

C pointers questions and answers subjective type



What is a pointer? How to make a pointer to pointer data type? Explain call by reference using pointers in c. Explain pointer to functions in c language.

Function pointers in C

Function Pointers are variables, which point to the address of a function. A running program gets a certain space in the main-memory. Both, the executable compiled program code and the used variables, are put inside this memory. Thus a function in the program code is nothing more than an address. Syntax to create function pointers in c
return type fnPointer* (arguments-list); We can assign address of similar function (with same arguments list, return type) by writing fnPointer=&fnName; // or fnPointer=fnName; Now we can call the function being pointed as fnPointer*(argument-list); Explain the use of generic pointers/void pointer in C. Generic pointers in C are useful when we want same variable to point to different variables at different times. Example c program for generic pointer (source:http://www.faqs.org/docs/learnc/x658.html): main() { int i; char c; void *the_data; i = 6; c = 'a'; the_data = &i; printf("the_data points to the integer value %d\n", *(int*) the_data); the_data = &c; printf("the_data now points to the character %c\n", *(char*) the_data); return 0; } Generic pointers cant be dereferenced directly. We cant write *the_data in above code. We need to first do type casting and then dereference them

You might also like