Sponsored Content
Full Discussion: pointer
Top Forums Programming pointer Post 89692 by sarwan on Tuesday 15th of November 2005 04:40:36 AM
Old 11-15-2005
pointer

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 10, how?

if we give cout<<q it will print the address, value won't print....

if we give cout<<p it will print the address, value won't print....

p has the base addr; q has addr of a[9].....

q-p+1

1 100 2 102 .......10 120

so, q-p here one position moved before now it has addr of a[8]...

q-p+1 now it's again get back to the a[9]....

i expected the output as address of a[9]......

but i got the output 10...(that is value at addr )

how value will come.....

warm regards
sarwan
 

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
geo_element(7rheolef)						    rheolef-6.1 					     geo_element(7rheolef)

NAME
geo_element - element of a mesh DESCRIPTION
Defines geometrical elements and sides as a set of vertice and edge indexes. This element is obtained after a Piola transformation from a reference element (see reference_element(2)). Indexes are related to arrays of edges and vertices. These arrays are included in the description of the mesh. Thus, this class is related of a given mesh instance (see geo(2)). EXAMPLE
This is the test of geo_element: geo_element_auto<> K; K.set_name('t') ; cout << "n_vertices: " << K.size() << endl << "n_edges : " << K.n_edges() << endl << "dimension : " << K.dimension() << endl << endl; for(geo_element::size_type i = 0; i < K.size(); i++) K[i] = i*10 ; for(geo_element::size_type i = 0; i < K.n_edges(); i++) K.set_edge(i, i*10+5) ; cout << "vertices: local -> global" << endl; for (geo_element::size_type vloc = 0; vloc < K.size(); vloc++) cout << vloc << "-> " << K[vloc] << endl; cout << endl << "edges: local -> global" << endl; for (geo_element::size_type eloc = 0; eloc < K.n_edges(); eloc++) { geo_element::size_type vloc1 = subgeo_local_vertex(1, eloc, 0); geo_element::size_type vloc2 = subgeo_local_vertex(1, eloc, 1); cout << eloc << "-> " << K.edge(eloc) << endl << "local_vertex_from_edge(" << eloc << ") -> (" << vloc1 << ", " << vloc2 << ")" << endl; } SEE ALSO
reference_element(2), geo(2) rheolef-6.1 rheolef-6.1 geo_element(7rheolef)
All times are GMT -4. The time now is 08:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy