11-15-2005
Quote:
Originally Posted by sarwan
void main()
{
int a[]={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a[9];
cout<<q-p+1<<endl;
}
the output is actually difference between the address locations and in this case the it happens to be 10.
p => address of start of array
q => address of 9th element.
((q-p) + 1) ==> (9 - 0) + 1 ==> 10..
Regards
10 More Discussions You Might Find Interesting
1. Programming
can u tell me the reson that why we should not delete a pointer twice.?
if we delete ponter twice then what happen and why this happen
Regards,
Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies
2. Programming
could any one tell why the following is showing segmentation fault while using **ptr
but working fine using **a
#include<stdio.h>
... (1 Reply)
Discussion started by: useless79
1 Replies
3. Programming
what is far pointer in C (1 Reply)
Discussion started by: useless79
1 Replies
4. Programming
Hi,
I am trying to divide my input to different type of out puts for some other use.
ex: logical_name : jkl00001
expected out put : model=jkl and num=00001
here is the code i actually written
/*******************************************************************/
void... (11 Replies)
Discussion started by: jagan_kalluri
11 Replies
5. Programming
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies
6. Programming
Can anyone tell me what the following statements do?
float (*tab);
tab=(float (*)) calloc(MAXCLASS,
(MAXCLASS+1)*sizeof(float)); (3 Replies)
Discussion started by: littleboyblu
3 Replies
7. Programming
Hi,
Can anyone tell me how i can declare and allocate dynamically an array of pointers to structured type?? Is declaration something like this:?
struct_name ** array; (1 Reply)
Discussion started by: littleboyblu
1 Replies
8. Programming
Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It.
Can someone help?
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int f1(char **str_);
int main(int argc, char **argv)
{
char *str = NULL;
f1(&str);
... (3 Replies)
Discussion started by: pharaoh
3 Replies
9. Programming
This code is to print out the program name and arguments list one by one:
1 #include<stdio.h>
2
3 void main(int argc, char *argv)
4 {
5 int iCount = 0;
6 while (iCount < argc) {
7 printf("argc:%d\t%s\n",iCount, argv);
8 ... (14 Replies)
Discussion started by: yifangt
14 Replies
10. Programming
Here are two programs that pass a pointer to a variable but behave differently. Shouldnt the i in second program be 0 after the function call?
#include<stdio.h>
void changeI(int *i)
{
*i = 10;
}
int main(void)
{
int i=5;
printf("%d before\n", i);
changeI(&i);
printf("%d... (1 Reply)
Discussion started by: dragonpoint
1 Replies
LEARN ABOUT DEBIAN
randbuffer
FBB::RandBuffer(3bobcat) random number streambuf FBB::RandBuffer(3bobcat)
NAME
FBB::RandBuffer - std::streambuf generating random numbers
SYNOPSIS
#include <bobcat/randbuffer>
Linking option: -lbobcat
DESCRIPTION
FBB:RandBuffer objects may be used as a std::streambuf of std::istream objects to allow the extraction of random numbers from the stream.
NAMESPACE
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
INHERITS FROM
std::streambuf
CONSTRUCTOR
o Randbuffer(int min, int max, size_t seed = 1):
This Randbuffer() constructor initializes the random generator. The seed is used to initialze the random number generator.Random
values between min and max (inclusive) are returned.
VIRTUAL MEMBERS
o int underflow():
This function is called by std::istream objects using Randbuffer. It produces the next available random number, separating the ran-
dom numbers by one blanks space. Random values between min and max (inclusive) are returned (see the description of the construc-
tor).
INHERITED MEMBERS
Since the class uses public derivation from std::streambuf, all members of this class can be used.
EXAMPLE
#include <iostream>
#include <istream>
#include <bobcat/randbuffer>
#include <bobcat/a2x>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
if (argc == 1)
{
cout << "expect: nruns min max seed
";
return 1;
}
Randbuffer rb(A2x(argv[2]), A2x(argv[3]), A2x(argv[4]).to<size_t>());
istream istr(&rb);
for (int idx = A2x(argv[1]); idx--; )
{
int c;
if (!(istr >> c))
{
cout << "extraction failed
";
break;
}
cout << "next: " << c << endl;
}
int count = 0;
while (istr.unget())
count++;
cout << "number of successful unget()-calls: " << count << endl;
istr.clear();
istr >> count;
cout << "and read: " << count << endl;
return 0;
}
FILES
bobcat/randbuffer - defines the class interface
SEE ALSO
bobcat(7), irandstream(3bobcat), rand(3), srand(3), std::streambuf
BUGS
None Reported.
DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature;
o bobcat_3.01.00-x.tar.gz: source archive;
o bobcat_3.01.00-x_i386.changes: change log;
o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries;
o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages;
o http://sourceforge.net/projects/bobcat: public archive location;
BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL).
AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl).
libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::RandBuffer(3bobcat)