Table of Contents
- 1 What precautions one must take while using pointers?
- 2 What are the disadvantages of using pointers in C++?
- 3 How can we prevent dangling pointers?
- 4 When should pointers be used?
- 5 What safety precautions should I take when working on electronic circuits?
- 6 What precautions should be taken when working with high voltage capacitors?
What precautions one must take while using pointers?
3 Answers
- Always initialize them.
- Check the bounds (size of pointer offset / index)
- free the memory when done.
- Set to NULL after freeing.
- Check they are not NULL before accessing.
- When you malloc, use thing = malloc(N * sizeof *thing)
- Don’t overwrite a pointer that was malloc ed before you free it.
- …
What are the disadvantages of using pointers in C++?
Using pointer in C programming has following disadvantages:
- If pointers are referenced with incorrect values, then it affects the whole program.
- Memory leak occurs if dynamically allocated memory is not freed.
- Segmentation fault can occur due to uninitialized pointer.
Should pointers be used in C++?
Pointers are extremely important, which allows us to access addresses and manipulate their contents. Pointer is also the most complex and difficult feature in C/C++ language. If we use pointers correctly, pointers can widely improve efficiency and performance. Each address location generally holds 8-bit of data.
How can we prevent dangling pointers?
The dangling pointer errors can be avoided by initializing the pointer to the NULL value. If we assign the NULL value to the pointer, then the pointer will not point to the de-allocated memory. Assigning NULL value to the pointer means that the pointer is not pointing to any memory location.
When should pointers be used?
Pointers are used to store and manage the addresses of dynamically allocated blocks of memory. Such blocks are used to store data objects or arrays of objects. Most structured and object-oriented languages provide an area of memory, called the heap or free store, from which objects are dynamically allocated.
What are some personal safety precautions to keep in mind?
Here are some personal safety precautions to keep in mind: • Always keep your work area dry. • Always work in a well-ventilated area. • Don’t wear flapping or loose clothing when working. • Don’t work with metallic jewelry on your hands like watches, rings and bracelets. • Don’t use bare hands to remove hot parts.
What safety precautions should I take when working on electronic circuits?
It’s important to ensure that you’re safe when working on electronic circuits. Here are some personal safety precautions to keep in mind: • Always keep your work area dry. • Always work in a well-ventilated area. • Don’t wear flapping or loose clothing when working.
What precautions should be taken when working with high voltage capacitors?
• Always wear insulator gloves in your hands when carrying out repairs. • When removing high-voltage charges on capacitors, always use a shorting stick. • Don’t hold the test prods when measuring voltage over 300V. • Always remove power to a circuit before connecting alligator clips. • Always wear safety goggles.