Solved

c programming

Posted on 2000-03-10
6
151 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
  • 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
max float value 3 60
Need some help with mailto 16 34
How to add columns to a RAD Studio FMX grid at design time 1 34
Need some help with design 17 22
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 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