Re: some C questions



On Wed, 23 May 2007 02:17:28 -0700, Guru Jois wrote:


Hai all,

I have some question. Please answer.

1. What is walking pointer?

If you're asking what I think you're asking, it's the process of iterating
through an array by incrementing a pointer, as below:

void copy(char *src, char *dst)
{
while(*src)
*dst++ = *src++;
*dst = 0;
}

Basically, we're "walking" through the src and dst arrays by incrementing
the pointers.

2. What is difference between procedure and subroutine?

Practically speaking, none. Some languages such as Fortran and Ada
distinguish between subroutines that return a value (functions) vs.
subroutines that don't return a value (procedures) with different syntax
and semantics (e.g., using different keywords to define the subroutine, or
preventing you from modifying input parameters of a function). C doesn't
make this distinction; all subroutines are functions.

3.What is template of main in C?

The standard prototypes for main are:

int main(void);
int main(int argc, char **argv);

Individual implementations may define additional prototypes, but
must support at least those two.

4. What is padding of structure ( or structure padding )?

Most architectures require that multibyte objects (ints, floats, doubles,
etc.) start on addresses that are multiples of 2 or 4. If you have a
struct that has a single char member followed by an int member, the
compiler will "pad" the struct so that the int member starts on the next
even address, so you wind up with a dummy byte between the members.

5. What is advantages of using pointers to functions?.

There are a number of advantages, from allowing for plug-in architectures
to introducing basic polymorphism. Unfortunately, I have to run out of
here before I can come up with any decent examples. It's something that
won't make sense until you've done a little more programming, anyway.
.



Relevant Pages

  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • Re: C# - getting binary data from .lib
    ... Use Marshal.AllocHGlobal to allocate the memory and pass this IntPtr to the ... int retCode = create(id, scale, ptrImage); ... You now control the pointer returned. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Another spinoza challenge
    ... You should test against the int type's limits: ... typedef struct complex ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: C# - getting binary data from .lib
    ... int create(int id, int scale, unsigned char *image); ... unsigned char* ptrImage = NULL; ... // Read through entire pointer byte by byte and put into managed array ...
    (microsoft.public.dotnet.framework.interop)
  • Re: C# - getting binary data from .lib
    ... then there is a problem with the ptrImage ... int retCode = create(id, scale, ptrImage); ... You now control the pointer returned. ...
    (microsoft.public.dotnet.framework.interop)