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
hostname
FBB::Hostname(3bobcat) Host Info FBB::Hostname(3bobcat)
NAME
FBB::Hostname - Contains name/address info about a host
SYNOPSIS
#include <bobcat/hostname>
Linking option: -lbobcat
DESCRIPTION
FBB::Hostname objects inherit from Hostent, and offers information about a host, like Hostent. Apart from being initialized by a hostname
or host address, they can also be initialized by a FBB::InetAddress object. Most of the functionality of an FBB::Hostname object is avail-
able through its parent-class FBB::Hostent.
NAMESPACE
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
INHERITS FROM
FBB::Hostent
CONSTRUCTORS
o Hostname():
The default constructor initializes an empty FBB::Hostname object.
o Hostname((std::string const &host)):
This constructor initializes an FBB::Hostname object from a string representing the name or dotted decimal address of a host. An
FBB::Errno object is thrown if the hostname information could not be retrieved.
o Hostname(InetAddress const &inetAddress):
This constructor initializes an FBB::Hostname object from an InetAddress object. An FBB::Errno object is thrown if the hostname
information could not be retrieved. The copy constructor is available.
MEMBER FUNCTIONS
All members of FBB::Hostent are available, as FBB::Hostname inherits from this class. There are no additional members.
EXAMPLE
#include <iostream>
#include <bobcat/hostname>
#include <bobcat/errno>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
while (true)
{
cout << "Enter name or address:
";
string str;
if (!getline(cin, str))
return 0;
if (str == "")
break;
try
{
Hostname h(str);
cout << "Official name:
";
cout << h.hostname() << endl;
cout << "Aliases:
";
for (size_t idx = 0; idx < h.nAliases(); idx++)
cout << h.alias(idx) << " ";
cout << endl;
cout << "Adresses:
";
for (size_t idx = 0; idx < h.nAddresses(); idx++)
cout << h.dottedDecimalAddress(idx) << " ";
cout << endl;
}
catch (Errno const &err)
{
cout << err.why() << endl;
}
}
return 0;
}
FILES
bobcat/hostname - defines the class interface
SEE ALSO
bobcat(7), hostent(3bobcat)
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::Hostname(3bobcat)