Sponsored Content
Full Discussion: pointer
Top Forums Programming pointer Post 89695 by parasa on Tuesday 15th of November 2005 05:41:31 AM
Old 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

why we never delete a pointer twice

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

pointer problem

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

far pointer

what is far pointer in C (1 Reply)
Discussion started by: useless79
1 Replies

4. Programming

Need help in character pointer

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

pass a pointer-to-pointer, or return a pointer?

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

matrix pointer

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

C dynamic pointer

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

Pointer to pointers

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

Pointer and address

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

Pointer confusion

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
FBB::OneKey(3bobcat)						One keystroke input					      FBB::OneKey(3bobcat)

NAME
FBB::OneKey - Single keystroke input, not requiring `Return' SYNOPSIS
#include <bobcat/onekey> Linking option: -lbobcat DESCRIPTION
OneKey objects may be used to realize `direct keyboard input': a pressed key becomes available without the need for pressing Enter. The characters are obtained from the standard input stream. Direct key entry remains in effect for as long as the OneKey object exists. Once the object is destroyed the standard input stream will return to its default mode of operation, in which input is `confirmed' by a newline character. NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
- ENUMERATION
The OneKey::Mode enumeration is used to control echoing of returned characters. It has two values: o OFF: returned characters are not echoed to the standard output stream; o ON: returned characters are echoed to the standard output stream. CONSTRUCTORS
o OneKey(OneKey::Mode state = OneKey::OFF): This constructor initializes the OneKey input object. By default, entered characters are not echoed. By constructing the object with the OneKey::ON argument, entered characters are echoed to the standard output stream. This construct throws an Errno exception if it not properly complete. The constructor may fail for the following reasons: o the standard input stream is not a tty (e.g., when the standard input stream is redirected to a file); o the current state of the standard input stream can't be determined; o the standard input stream's state can't be changed to the `direct keyboard input' mode. The copy constructor (and the overloaded assignement operator) are not available. MEMBER FUNCTIONS
o int get() const: Returns the next character from the standard input stream, without the need for pressing Enter. o void setEcho(OneKey::Mode state): Changes the echo-state of the OneKey object. The argument may be either OneKey::ON or OneKey::OFF. o void verify() const: Obsoleted, will be removed in a future Bobcat release. EXAMPLE
/* driver.cc */ #include <iostream> #include <string> #include <bobcat/onekey> using namespace std; using namespace FBB; int main() { try { OneKey onekey; onekey.verify(); cout << "Usage: 1: next chars are echoed, 0: no echo, q: quits "; while (true) { char c; cout << "ready... "; cout << "Got character '" << (c = onekey.get()) << "' "; switch (c) { case '1': onekey.setEcho(OneKey::ON); break; case '0': onekey.setEcho(OneKey::OFF); break; case 'q': return 0; } } } catch (Errno const &e) { cout << e.why() << endl; return e.which(); } } FILES
bobcat/onekey - defines the class interface SEE ALSO
bobcat(7) 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::OneKey(3bobcat)
All times are GMT -4. The time now is 07:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy