Solved

c programming

Posted on 2000-03-10
6
147 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
Comment Utility
thank  you for your cooperation
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
Comment Utility
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
Comment Utility
sir,i have not got all thE answer.if possible,please answer others.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now