Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pointers in C

Posted on 2003-10-29
6
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:harris_c
ID: 9647838
Assignment?
0
 
LVL 2

Accepted Solution

by:
mrd_2k earned 100 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 100 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Make the most of your online learning experience.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

604 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