Solved

c programming

Posted on 2000-03-10
6
152 Views
Last Modified: 2010-04-02
please explain with examples call by value and call by pointers?
explain how the pointers arithmatics takes place.Alloc.h and type.h
have what functions?
0
Comment
Question by:mohua_banerjee
[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
  • 3
  • 2
6 Comments
 

Author Comment

by:mohua_banerjee
ID: 2604743
thank  you for your cooperation
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 2604818
in call by value you pass a copy of a value to a function, like

void F(int i) // i is a copy of a value passed.
{
   i = 5; // changes copy of value passed.
}

int main()
{
   int x = 1;
   F(x);  // does not change x.
}

In call by reference, a reference or pointer to the specified value is passed This reference may be used to change the actual value that was specified

void F(int *iptr) // Pointer to an int is passed.
{
   *i = 5; // changes value of caller's int.
}

int main()
{
   int x = 1;
   F(&x);  // Changes x.
}
0
 

Author Comment

by:mohua_banerjee
ID: 2605426
sir,i have not got all thE answer.if possible,please answer others.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 2605481
I don't know what

>> explain how the pointers arithmatics takes
>> place.Alloc.h and type.h
>> have what functions?

means.  It doesn't make sense.

Also EE rules do state that you should only ask 1 question per EE question.   They also recommend a 50 point value for an easy question, 20 points for 2 questions is too little. I will answer the 2nd question--if you can explain it, but in the future try to ask only 1 question at a time and assign them fair point values.
0
 
LVL 3

Expert Comment

by:Iexpert
ID: 2606493
I haven't a clue what you mean in the 2nd part of the question.

A note on pinter arithmetic though,
is that you can subtract pointers to
find out how much space between them
e.g:

char *p1, *p2;
p1 = "My String"
p2 = p1 + 3;

//p2 - p1 == 3
//p1 = "My String"
//p2 = "String"

//Because p1 is a pointer to char
//the following moves the address of
//p1 up 3 chars (bytes)
p1+=3;

//NB The above operation is dependent
//on type. Therefore:
int* p3;
int test[]={1,2,3,4};
p3 = &test;

//The following makes *p3 == 2
//even though an int take up 2 bytes
//memory. The compiler works this out
//automatically for you
p3++;

As for alloc.h, these functions
are for dynamically creating memory
on the heap.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2608200
mohua_banerjee,
   You offered a very low point value for this question, then when I answered it, you gave me a bad grade too!  You should only give a low grade if the answer is incorrect.  My answer was not incorrect.  If you don't understand the answer you can ask for clarification, but to simply grade a question with a low grade for no reason is not fair.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

695 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