Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Plan your Crypto & Forex entries before you take the trade
romeshnonis
Updated:
Today at 3:20 AM
RHCSA, RHCE, AWS, Docker, Kubernetes Training
Sanjeewani95
Updated:
Tuesday at 10:28 AM
🛡️ Kaspersky Antivirus – 1 Year / 1 Device | Rs. 2,300 | Only 9 Left
KSPathirana
Updated:
Sep 7, 2026
Ad icon
Professional CCTV Installation Service
Techguy231
Updated:
Sep 6, 2026
Ad icon
I'll research & write an article - Rs. 2000 onwards
Blogerwiki
Updated:
Sep 3, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
store arrays using a pointer
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Arkham Knight" data-source="post: 16464982" data-attributes="member: 500755"><p>දෙවැනි එක මම Algorithm එකක් හදලා හොද විදියට හැදුවා එතකොට Array එක 1000+ ලොකු වුනත් මේක වැඩ එළට. </p><p></p><p>Algorithm එකේ basic principle එක මෙතන පැහැදිලි කරලා ඇති.</p><p></p><p>පළවෙනි space එකේ තියෙන එක යනවා temp variable එකකට</p><p>ඊට පස්සේ last space එකේ තියෙන value එක යනවා පළවෙනි space එකට. </p><p>ඊට පස්සේ මේක දිගටම ඒ විදියට වෙනවා.</p><p></p><p>මේකේ පළවෙනි සහා last space එක අදුන ගන්නේ </p><p></p><p>int temp = *(pInput + i);</p><p> *(pInput + i) = *(pInput + numCount -1 - i);</p><p> *(pInput + numCount -1 - i) = temp;</p><p></p><p>මේ code එකෙන් </p><p></p><p>point එකක් array එකකට point කරාම</p><p></p><p>ඒකේ *pInput එක return කරන්නේ array එකේ පළවෙනි space එකේ value එකයි.</p><p>දෙවැනි space එකට යන්න ඕනේනම්</p><p>*(pInput + 1) දාන්න ඕනේ , 3 වැනි space එකට නම් *(pInput + 2) </p><p>එතකොට හැම තිස්සේම count - 1= index number එකයි.</p><p>මෙතන index number එක තමයි 1,2, කියලා යන්නේ. </p><p></p><p>*(pInput + numCount -1 - i)</p><p>එකෙන් කරන්නේ</p><p>numCount = 5 (array එකේ values 5 තියෙනවා නම්)</p><p>පළවෙනි iteration එකේදි i = 0</p><p></p><p>එතකොට </p><p>*(pInput + 5 -1 - 0) එක point out වෙන්නේ array එකේ</p><p>*(pInput + 4) last space එකට 4 තමයි last space එකේ index එක (count - 1= index number )</p><p></p><p>එතකොට මෙතන වෙන දේ තමයි පහළ තියෙන්නේ</p><p></p><p>int temp = *(pInput + i); // 1</p><p> *(pInput + i) = *(pInput + numCount -1 - i); // 2</p><p> *(pInput + numCount -1 - i) = temp; // 3</p><p></p><p>පින්තූරේ තියෙන 1,2,3 follow කරන්න එතකොට තේරුම් ගන්න ලේසියි</p><p></p><p></p><p><img src="http://i.imgur.com/idz85SE.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p></p><p></p><p>[code]</p><p></p><p>void qTwo()</p><p>{</p><p> int *pInput = &sVar[0];</p><p> int tempVar;</p><p> int numCount = (sizeof(sVar)/sizeof(sVar[0]));</p><p></p><p> //reverse the number order</p><p> for(int i=0;i< numCount/ 2;i++)</p><p> {</p><p> int temp = *(pInput + i);</p><p> *(pInput + i) = *(pInput + numCount -1 - i);</p><p> *(pInput + numCount -1 - i) = temp;</p><p> }</p><p></p><p> cout << "typed values in reverse order" << endl;</p><p> for(int i=0;i<5;i++)</p><p> {</p><p> cout << sVar[i] << endl;</p><p> }</p><p>}</p><p></p><p>[/code]</p></blockquote><p></p>
[QUOTE="Arkham Knight, post: 16464982, member: 500755"] දෙවැනි එක මම Algorithm එකක් හදලා හොද විදියට හැදුවා එතකොට Array එක 1000+ ලොකු වුනත් මේක වැඩ එළට. Algorithm එකේ basic principle එක මෙතන පැහැදිලි කරලා ඇති. පළවෙනි space එකේ තියෙන එක යනවා temp variable එකකට ඊට පස්සේ last space එකේ තියෙන value එක යනවා පළවෙනි space එකට. ඊට පස්සේ මේක දිගටම ඒ විදියට වෙනවා. මේකේ පළවෙනි සහා last space එක අදුන ගන්නේ int temp = *(pInput + i); *(pInput + i) = *(pInput + numCount -1 - i); *(pInput + numCount -1 - i) = temp; මේ code එකෙන් point එකක් array එකකට point කරාම ඒකේ *pInput එක return කරන්නේ array එකේ පළවෙනි space එකේ value එකයි. දෙවැනි space එකට යන්න ඕනේනම් *(pInput + 1) දාන්න ඕනේ , 3 වැනි space එකට නම් *(pInput + 2) එතකොට හැම තිස්සේම count - 1= index number එකයි. මෙතන index number එක තමයි 1,2, කියලා යන්නේ. *(pInput + numCount -1 - i) එකෙන් කරන්නේ numCount = 5 (array එකේ values 5 තියෙනවා නම්) පළවෙනි iteration එකේදි i = 0 එතකොට *(pInput + 5 -1 - 0) එක point out වෙන්නේ array එකේ *(pInput + 4) last space එකට 4 තමයි last space එකේ index එක (count - 1= index number ) එතකොට මෙතන වෙන දේ තමයි පහළ තියෙන්නේ int temp = *(pInput + i); // 1 *(pInput + i) = *(pInput + numCount -1 - i); // 2 *(pInput + numCount -1 - i) = temp; // 3 පින්තූරේ තියෙන 1,2,3 follow කරන්න එතකොට තේරුම් ගන්න ලේසියි [IMG]http://i.imgur.com/idz85SE.png[/IMG] [code] void qTwo() { int *pInput = &sVar[0]; int tempVar; int numCount = (sizeof(sVar)/sizeof(sVar[0])); //reverse the number order for(int i=0;i< numCount/ 2;i++) { int temp = *(pInput + i); *(pInput + i) = *(pInput + numCount -1 - i); *(pInput + numCount -1 - i) = temp; } cout << "typed values in reverse order" << endl; for(int i=0;i<5;i++) { cout << sVar[i] << endl; } } [/code] [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom