Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Access the data through array index or pointer is exactly equivalent. Go through the below program with me...</p> <p>There are a loop which continues to 100 times but when we see disassemble code that there are the data which we access through has least instruction comparability to access through array Index</p> <p>But it doesn't mean that accessing data through pointer is fast actually it's depend on the instruction which performed by compiler.Both the pointer and array index used the address array access the value from offset and increment through it and pointer has address. </p> <pre><code>int a[100]; fun1(a,100); fun2(&amp;a[0],5); } void fun1(int a[],int n) { int i; for(i=0;i&lt;=99;i++) { a[i]=0; printf("%d\n",a[i]); } } void fun2(int *p,int n) { int i; for(i=0;i&lt;=99;i++) { *p=0; printf("%d\n",*(p+i)); } } disass fun1 Dump of assembler code for function fun1: 0x0804841a &lt;+0&gt;: push %ebp 0x0804841b &lt;+1&gt;: mov %esp,%ebp 0x0804841d &lt;+3&gt;: sub $0x28,%esp`enter code here` 0x08048420 &lt;+6&gt;: movl $0x0,-0xc(%ebp) 0x08048427 &lt;+13&gt;: jmp 0x8048458 &lt;fun1+62&gt; 0x08048429 &lt;+15&gt;: mov -0xc(%ebp),%eax 0x0804842c &lt;+18&gt;: shl $0x2,%eax 0x0804842f &lt;+21&gt;: add 0x8(%ebp),%eax 0x08048432 &lt;+24&gt;: movl $0x0,(%eax) 0x08048438 &lt;+30&gt;: mov -0xc(%ebp),%eax 0x0804843b &lt;+33&gt;: shl $0x2,%eax 0x0804843e &lt;+36&gt;: add 0x8(%ebp),%eax 0x08048441 &lt;+39&gt;: mov (%eax),%edx 0x08048443 &lt;+41&gt;: mov $0x8048570,%eax 0x08048448 &lt;+46&gt;: mov %edx,0x4(%esp) 0x0804844c &lt;+50&gt;: mov %eax,(%esp) 0x0804844f &lt;+53&gt;: call 0x8048300 &lt;printf@plt&gt; 0x08048454 &lt;+58&gt;: addl $0x1,-0xc(%ebp) 0x08048458 &lt;+62&gt;: cmpl $0x63,-0xc(%ebp) 0x0804845c &lt;+66&gt;: jle 0x8048429 &lt;fun1+15&gt; 0x0804845e &lt;+68&gt;: leave 0x0804845f &lt;+69&gt;: ret End of assembler dump. (gdb) disass fun2 Dump of assembler code for function fun2: 0x08048460 &lt;+0&gt;: push %ebp 0x08048461 &lt;+1&gt;: mov %esp,%ebp 0x08048463 &lt;+3&gt;: sub $0x28,%esp 0x08048466 &lt;+6&gt;: movl $0x0,-0xc(%ebp) 0x0804846d &lt;+13&gt;: jmp 0x8048498 &lt;fun2+56&gt; 0x0804846f &lt;+15&gt;: mov 0x8(%ebp),%eax 0x08048472 &lt;+18&gt;: movl $0x0,(%eax) 0x08048478 &lt;+24&gt;: mov -0xc(%ebp),%eax 0x0804847b &lt;+27&gt;: shl $0x2,%eax 0x0804847e &lt;+30&gt;: add 0x8(%ebp),%eax 0x08048481 &lt;+33&gt;: mov (%eax),%edx 0x08048483 &lt;+35&gt;: mov $0x8048570,%eax 0x08048488 &lt;+40&gt;: mov %edx,0x4(%esp) 0x0804848c &lt;+44&gt;: mov %eax,(%esp) 0x0804848f &lt;+47&gt;: call 0x8048300 &lt;printf@plt&gt; 0x08048494 &lt;+52&gt;: addl $0x1,-0xc(%ebp) 0x08048498 &lt;+56&gt;: cmpl $0x63,-0xc(%ebp) 0x0804849c &lt;+60&gt;: jle 0x804846f &lt;fun2+15&gt; 0x0804849e &lt;+62&gt;: leave 0x0804849f &lt;+63&gt;: ret End of assembler dump. (gdb) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload