Advantages & Disadvantages of C Programming

What are the advantages and disadvantages of pointer in C language?

The main advantages of using pointers are
1.) Function cannot return more than one value. But when the same function can modify many pointer variables and function as if it is returning more than one variable.
2.) In the case of arrays, we can decide the size of th array at runtime by allocating the necessary space.
3.) In the case of pointers to classes, we can use polymorphism and virtual classes to change the behavior of pointers to various types of classes at runtime

Coming to the disadvantages of pointers
1.) If sufficient memory is not available during runtime for the storage of pointers, the program may crash (least possible)
2.) If the programmer is not careful and consistent with the use of pointers, the program may crash (very possible)

A brief synopsis on the "rules" of pointers
1.) Always initialize a pointer by calling an allocator
2.) Alway check to see if the allocation request failed
3.) Always deallocate memory controlled by a pointer when done with it
4.) Never access memory that has not been allocated – pay attention to the size of arrays
5.) Never access memory that has been deallocated
6.) Do not allocate and deallocate memory with wild abandon, because that can fragment the virtual memory address space, causing future allocation requests to fail – particularly in long running programs such as web servers

There are more advantages and disadvantages than these – these are but a few examples.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: