Solved

Pointers in C

Posted on 2003-10-29
6
267 Views
Last Modified: 2010-04-17
1) Why pointers are used apart from the adv that they r very useful during dynamic memory allocation?
2) What is the use of function pointers?
3) What is the difference between static functions and ordinary functions? how r static functions useful?
4) Can u change the value of a macro dynamically?
5) What is #pragma? At what circumstances it should be used?
6) How to invoke someother user defined function before main?
Eg: void func() { printf("Hi" ); }
void main() { printf("Hello" ); }

i want the o/p as Hi Hello. how to invoke func() before main()
     
0
Comment
Question by:LeelaSwamy
6 Comments
 
LVL 8

Expert Comment

by:harris_c
ID: 9647838
Assignment?
0
 
LVL 2

Accepted Solution

by:
mrd_2k earned 25 total points
ID: 9648063
1) Why pointers are used apart from the adv that they r very useful during dynamic memory allocation?
You can traverse arrays, reference and manipulate data within a larger body, pass references to large amounts of data that would be slow to copy
2) What is the use of function pointers?
use your imagination ;) you can have multiple functions with the same prototype, but different functionality invoked via a pointer.
3) What is the difference between static functions and ordinary functions? how r static functions useful?
static CLASS MEMBER functions don't have a 'this' pointer, can't access instance data. however they can be invoked as a normal function is, without a cooresponding class instance.
4) Can u change the value of a macro dynamically?
im not quite sure what you mean. macros generate code, before the code is actually compiled
5) What is #pragma? At what circumstances it should be used?
pragmas are compiler-specific directives that perform specific functions not addressed in the language standards. alot of machine and os-specific functionality is addressed
6) How to invoke someother user defined function before main?
Eg: void func() { printf("Hi" ); }
void main() { printf("Hello" ); }
you shouldn't ever need to. main() signifies your program's entry point. you should build your code around it.

0
 
LVL 1

Assisted Solution

by:SergioSaraiva
SergioSaraiva earned 25 total points
ID: 9648938
Is this homework?

Some of this answers where simple copy-paste from msdn (http://www.msdn.com), as I could not make better...


1) Why pointers are used apart from the adv that they r very useful during dynamic memory allocation?

Pointers are the most powerful (and difficult) way to manipulate memory data. You can use pointers to change values by reference, to travel through arrays (continuous memory block), etc

2) What is the use of function pointers?

Imagine you want to implement a generic sort function. This function should sort an array of any type. For that you will need the array, the type size, and a function which compares two values of the type specified. Then, your sort function should use this “user defined” function to compare each value of the array, in order perform the algorithm. Each time you want to sort a new type of data, all you have to is to implement this compare function and pass it to the sort function (which does not need to be touched).
To pass the compare function to the sort function, you can use a function pointer.

3) What is the difference between static functions and ordinary functions? how r static functions useful?

Static member functions are considered to have class scope. In contrast to nonstatic member functions, these functions have no implicit this argument; therefore, they can use only static data members, enumerators, or nested types directly.

4) Can u change the value of a macro dynamically?

No. Macros are expanded before the code is actually compiled.

5) What is #pragma? At what circumstances it should be used?

Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler.

6) How to invoke someother user defined function before main?
Eg: void func() { printf("Hi" ); }
void main() { printf("Hello" ); }

i want the o/p as Hi Hello. how to invoke func() before main()


There is no way of doing that. And if you ever watch something similar, close you eyes not to see it…

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get boolean result of md5sum from two files in powershell 8 77
Looking for example pivot year code used in Y2K 4 68
Device same like our heart 12 86
Help Required 3 97
A short article about a problem I had getting the GPS LocationListener working.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question