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
TAU_MAPPING_LINK(3)						  TAU Mapping API					       TAU_MAPPING_LINK(3)

NAME
TAU_MAPPING_LINK - Creates a mapping link SYNOPSIS
C/C++: TAU_MAPPING_LINK(FunctionInfo FuncIdVar, unsigned long Key); DESCRIPTION
TAU_MAPPING_LINKcreates a link between the object defined in TAU_MAPPING_OBJECT (that identifies a statement) and the actual higher-level statement that is mapped with TAU_MAPPING. The Key argument represents a profile group to which the statement belongs, as specified in the TAU_MAPPING macro argument. For the example of array statements, this link should be created in the constructor of the class that represents the expression. TAU_MAPPING_LINK should be executed before any measurement takes place. It assigns the identifier of the statement to the object to which FuncIdVar refers. For example EXAMPLE
C/C++ : class MyClass { public: MyClass() { } ~MyClass() { } void Run(void) { TAU_MAPPING_OBJECT(runtimer) TAU_MAPPING_LINK(runtimer, (unsigned long) this); TAU_MAPPING_PROFILE(runtimer); // For one object TAU_PROFILE("MyClass::Run()", " void (void)", TAU_USER1); /* ... */ } }; int main(int argc, char **argv) { TAU_PROFILE_INIT(argc, argv); TAU_PROFILE("main()", "int (int, char **)", TAU_DEFAULT); MyClass x, y, z; MyClass a; TAU_MAPPING_CREATE("MyClass::Run() for object a", " " , (TauGroup_t) &a, "TAU_USER", 0); TAU_MAPPING_CREATE("MyClass::Run() for object x", " " , (TauGroup_t) &x, "TAU_USER", 0); TAU_PROFILE_SET_NODE(0); cout <<"Inside main"<<endl; a.Run(); x.Run(); y.Run(); SEE ALSO
TAU_MAPPING_CREATE(3), TAU_MAPPING_OBJECT(3), TAU_MAPPING_PROFILE(3) 08/31/2005 TAU_MAPPING_LINK(3)
All times are GMT -4. The time now is 03:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy