answersLogoWhite

0


Best Answer
Copy

The main drawback is that they're a bit more difficult to use than references. References always point to valid data (they can never be NULL), but pointers may be NULL or may point to arbitrary data, including other pointers. The programmer is therefore entirely responsible for ensuring their pointers point at valid data before they can actually use that data; the compiler is not able to foretell the runtime condition of a pointer. When there is a choice between using a reference or a pointer to a reference, the reference is the preferred choice. But if there's any chance the reference could be NULL, a pointer must be used instead.

If memory is allocated to a pointer (using malloc or new), the programmer is responsible for releasing that memory, otherwise a memory leak will occur. By contrast, references will fall from scope automatically. However, a danger here is that the programmer may point to a reference that falls from scope, leaving a dangling pointer. Any attempt to access that pointer may result in a runtime error (if not, it is a "time-bomb" which may crash the program at a later time, with no indication as to the cause).

Pointers can also be used to "rove" within the data of an object, a structure or an array. While this is a powerful feature, great care must be taken to ensure the data is valid. For instance, overrunning a data buffer is a common source of errors and can lead to exploitation by hackers who may be able to inject arbitrary code into your code, with all the same privileges of the original code. This is particularly dangerous when functions accept pointers to unchecked data buffers which can overwrite the return address of the function to point at the "infected" code in the buffer.

While there are drawbacks to using pointers, with appropriate usage they make it possible to produce more efficient code than might otherwise be possible with references alone. Thus the only real drawback is when they are used inappropriately.

User Avatar

Wiki User

โˆ™ 2012-06-27 16:06:43
This answer is:
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar

Add your answer:

Earn +5 pts
Q: What are the drawbacks of using pointers in C?
Write your answer...
Submit

Related Questions

What are the pointers in computer programming using c?

addresses


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Why java doesn't support pointer?

Pointers are a concept in C wherein the programmer can access the system memory and process it. Pointers are considered the most complex as well as confusing part of the C programming language. almost all C programs using pointers had hours of time spent by the programmers to sort out errors they induced in their code using pointers. So Java conveniently avoided pointers :)


C program to add 2 matrices using pointers?

this is immpossible


How do you find the biggest of n numbers using pointers in C?

yes


What are the applications of pointers in using c language?

Accessing data by address. Some data-structures, like lists and trees, are usually implemented using pointers.


Uses of pointers?

In computer terminology, pointer is a programming language. It is an important part of C language. Uses of pointers: C pointer, C arrays, C linked list, memory-mapped hardware, Pass-by-address using pointers, Dynamic memory allocation.


How can you access the administrator password using pointers in C?

i don't have any knowledge about your ques. but i guide you to read the "Writing TSR through C" & learn knowledge of FAR & HUGE ponters.by this you can access the adminstrator password using pointers in C.


How do you run graphics program in C?

pro c language to implement linear search using pointers


Why are header files not required when using far and near pointers?

In C programming, header files are required. It doesn't matter if you are using near pointers, far pointers, both, or neither -- you still need header files. There is no connection between the necessity of header files and the pointers' size.


C program to convert rectangular coordinate to polar coordinate using pointers?

Cartesian coordinates c language


Write a c program to copy two strings using pointers?

nahi malum


What is the reason using pointer in c?

We can use pointers in user defined functions, the reason behind is we can access the actual parameters indirectly by using pointers. And also we can reduce the length of a complicated program into very small code. It is easy to manipulate with pointers.


How to find mean variance and standard deviation using functions in c program?

to calculate standard deviation using pointers


Is it possibly to return an array of strings in a function without using pointers in C plus plus?

No.


C program to combine two array elements without duplicate using pointers?

jjk,


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


What is main topics in c language?

1. Basics of C 2. Pointers 3. Function Pointers 4. Pointers Arithmetic 5. Most Important playing with pointers. 6. Algorithm to Solve Problems


What is stream pointer in c?

C does not have stream pointers.


What is the use of pointers in C programming Language?

Pointer is a variable which points to the address of another variable. Pointers come handy when we are left with no choices such as calling a function using "pass by reference" method, using memory allocated dynamically etc...


What is the difference between pointers in C and pointers in C plus plus?

A pointer is simply a variable that can store a memory address and has the same purpose in both languages. The only real difference is that C++ pointers can point at objects (instances of a class) and indirectly invoke their methods, whereas pointers in C (which is not object oriented) cannot.


What is the source code for attendance record system in c language using pointers functions arrays whichever required?

bmbmbvjmgjmgj


Why pointers are eliminated from java?

The appropriate term would be "Pointers were avoided when Java was created" The C language gives access to its memory to the developer which gives great powers to the programmer but its like giving a dynamite. Pointers caused more harm than good to the developers world over while using the C language. Any C developer you talk to would have a story to narrate regarding his tough experience with pointers. Hence the team that created the Java language took a decision to avoid the concept of Pointers from this new language they were creating. Hence Java doesnt have pointers.


What is the use of huge pointer in C?

It has to do with the memory model you are using... If you are using the LARGE or HUGE memory model, then you use HUGE memory pointers. == Huge pointers are like far pointers, just more so: they are always normalized (ie offset part is between 0 and 15), and segment wrapping-around do not occur if you use them.