18. 9. 2013

Programování C/C++. Parameter funkce odkazem

Vsadím se, že jste to zaisté zkoušeli, předát parameter funkce pomocí její reference v prostředí pro ANSI C případně C99 a hodilo Vám to hlášku (třeba v překladači Mingw):

... error: expected ';', ',' or ')' before '&' token ...

,protože jste se snažili zkompilovat následující ukázku programu:

void test(u8 &a) {
 a++;
}

Důvod, proč to nejde zkompilovat, je ten že předávání parametru funkce pomocí reference, jde pouze u jazyku C++ a ne u jazyka C a ani u jazyka objective-C.

A když už jsme u reference, tak se podívejte na následující ukázku:

int main(void) {
 u8 b=1;
 test(b);
 cout << "b=" << b << endl;
}

Po spuštění programu bude hodnota b=2. A to je z toho důvodu že se vezme reference lokální proměnné b. Ta se předá jako parameter do funkce test, tam se inkrementuje hodnota na kterou reference ukazuje a tím se změní i hodnota proměnné b protože reprezentuje to samé pamětové místo.

Zdroj: Passing arguments by reference
S pozdravem
ViaExplore - Tomáš Kamenický

43 komentářů:

VEDA řekl(a)...

Awesome post. It’s so interesting to read
I loved this already .
Hey guys, looking for extraordinary site?
Just click the link below
카지노사이트

https://yhn777.com 카지노사이트

SEO CANADA řekl(a)...

I love the way you write and share your niche! Very interesting and different! 먹튀검증

SEO CANADA řekl(a)...

Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you 안전놀이터

SEO CANADA řekl(a)...

There are several dissertation web sites on the net once you locate unsurprisingly explained in the website 먹튀

SEO CANADA řekl(a)...

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained 파워볼사이트

SEO CANADA řekl(a)...

I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. 먹튀폴리스

SEO CANADA řekl(a)...

Our team is motivated and dedicated to providing you a seamless experience when it comes. 먹튀검증

SeoMaster789 řekl(a)...

Keep up the good work; I read few posts on this website, including I consider that your blog is fascinating and has sets of the fantastic piece of information. Thanks for your valuable efforts 안전놀이터

Unknown řekl(a)...

Hmm… I interpret blogs on a analogous issue, however i never visited your blog. I added it to populars also i’ll be your faithful primer 메이저놀이터

office laptop002 řekl(a)...

This is really intriguing, You’re an especially efficient writer. I have signed up with your feed additionally look ahead to finding your personal interesting write-ups. Furthermore, I’ve got shared the blog inside our social networks. 먹튀검증

Robert řekl(a)...

Because of this it will be significantly better which you could suitable studies just before manufacturing. You'll be able to create significantly greater guide that way. 먹튀폴리스

안전놀이터 řekl(a)...

Thanks again for the blog.Really looking forward to read more. Really Great 안전놀이터

office laptop řekl(a)...

I am really very happy to visit your blog. Now I am found which I actually want. Thanks a lot for sharing a piece of wonderful information which I am looking for a longer period of time 안전놀이터

Linda řekl(a)...

Congratulations for posting such a useful blog. Your blog isn’t only informative but also extremely artistic to 토토사이트

bmb řekl(a)...

Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it 먹튀검증커뮤니티

Robert řekl(a)...

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. The sims : Discover university is now available worldwide on PC! Your dorm room is ready for you, dom't be late for your first day of class 토토사이트

Unknown řekl(a)...

When do you think this Real Estate market will go back up? Or is it still too early to tell? We are seeing a lot of housing foreclosures in Longwood Florida. What about you? We would love to get your feedback on this. 먹튀검증

Horon Monia řekl(a)...

I read your blog frequently and I just thought I’d say keep up the amazing work! 안전놀이터

SeoMaster789 řekl(a)...

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. 먹튀검증

kh řekl(a)...

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good wor 토토사이트

슈어맨 řekl(a)...

 I got so interested in this material that I couldn’t stop reading. Your blog is really impressive 슈어맨

Robert řekl(a)...

I was taking a gander at some of your posts on this site and I consider this site is truly informational! Keep setting up 먹튀검증사이트

Daniel řekl(a)...

Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work courtier immobilier aylmer

온라인카지노 řekl(a)...

Thanks for another wonderful post. Where else could anybody get that type of info in such an ideal way of writing? 토토사이트

Muna řekl(a)...

Thanks for this wonderful post! It has long been very helpful. I wish that you’ll carry on posting your wisdom with us. courtier immobilier Candiac

yoga gatineau řekl(a)...

Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. yoga gatineau

Henry Jacob řekl(a)...

Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’r wait to read more posts. 먹튀검증사이트

charles majic řekl(a)...

Thanks for this post.It was really interesting to read. 먹튀검증업체

Unknown řekl(a)...

Always so interesting to visit your site.What a great info, thank you for sharing. this will help me so much in my learning 메이저사이트 추천

Ali Murad řekl(a)...

I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work 먹튀검증

Alex kk řekl(a)...

토토사이트 TEN BET
토토사이트 TEN BET은 검증 된 토토사이트로 다양한 이벤트를 통해 현재 신규회원에게 첫 충전 30%와 매 충전 10%를 지급하고 있습니다 메이저사이트
.

Hibbah řekl(a)...

There is a lot of controversy in the back of the DankWoods Flavors brand. residing within the Bay vicinity, i will’t discover it in any of the large call dispensaries and shipping offerings around here. dankwoods

Hibbah řekl(a)...

Dankwoods comes in part from the popular Backwoods Smokes brand of cigarillos. These cigarillos are rolled with a Connecticut Broadleaf tobacco leaf, which must be of remarkable quality. dankwoods

Hibbah řekl(a)...

led grow light produced by Spider Farmer integrated with Samsung Diodes that offers full spectrum and wavelength for optimum growth of plants and vegetables in your grow tent or indoor garden. led grow light

Hibbah řekl(a)...

Love to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks. iPhone screen not responding to touch

Hibbah řekl(a)...

very interesting post.this is my first time visit here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post! Readabiography

Hibbah řekl(a)...

Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!! Raja Ampat Holidays

Hibbah řekl(a)...

I found this is an informative and interesting post so i think so it is very useful and knowledgeable. I would like to thank you for the efforts you have made in writing this article. Online Casino in Singapore

Hibbah řekl(a)...

Dankwoods pre rolls brings you the highest quality medical cannabis in a convenient, easy to smoke product. Dankwoods

I will fix HTML, CSS, js, PHP, bootstrap bugs on your website within 12 hours řekl(a)...

Good day very cool website!! Man .. Excellent .. Superb .. I’ll bookmark your website and take the feeds additionally. I am glad to find a lot of useful information right here in the put up, we want to develop more strategies in this regard, thanks for sharing.

Hibbah řekl(a)...

The lottery price price tag on-line At present, it should be admitted that there are numerous numbers which might be scattered withinside the social world. But one element and the maximum crucial element is that Most of the time while we visit wager with the supplier, maximum people may be hit with a confined number. And even extra merciless is that we're advised with the aid of using the supplier that if you could wager, you most effective need to pay half. lottovip

Working Shop org řekl(a)...

Workshopmanuals is an online-based trustworthy platform for everyone. Here You can find the workshop repair manual, Wiring diagrams, Cars, Trucks & Van's repair manuals with 24/7 Live chat support Visit Website

Workshopmanuals ORG řekl(a)...

Download Workshop Repair Manuals, Wiring Diagrams, EPC's for all cars, vans, trucks, lorries, etc. Petrol, gasoline, diesel, hybrid PDF & OEM from Workshopmanuals org