• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 12:42
CET 18:42
KST 02:42
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced14[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband BGE Stara Zagora 2026 announced Information Request Regarding Chinese Ladder SC: Evo Complete - Ranked Ladder OPEN ALPHA
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions Which season is the best in ASL? FlaSh's Valkyrie Copium BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
The Perfect Game Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread Should offensive tower rushing be viable in RTS games?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1123 users

C Programming Practice - Page 4

Blogs > CecilSunkure
Post a Reply
Prev 1 2 3 4 All
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
November 05 2012 04:35 GMT
#61
On November 05 2012 13:31 frogmelter wrote:
Show nested quote +
On November 05 2012 13:25 obesechicken13 wrote:
1) Code a case to check if it is a prime number to begin with. If it isn't, then enter the loop

If I could do this I'd be a millionaire.


It can find the prime factors of 9,223,372,036,854,775,808 pretty fast [sub 5 seconds].

Lol. I don't know if you're trolling or if you misunderstand the problem. But That number above has only one prime factor: 2.


I'm not trolling.

Since the algorithm divides, it will come up with the answer pretty fast. The factors are 2^63, and every pass will divide it by 2. Meaning the loop only needs to run 63 times.

The problem occurs when you have a huge jump, like the first prime factor is like 6,000,000,000+ or so.

Ok. well you seem to know more than I gave you credit for then.

I'm not sure if it is possible to prove if a(any) number that large is prime in 5 seconds. I just heard from wikipedia that:
There is no known useful formula that yields all of the prime numbers and no composites.


http://en.wikipedia.org/wiki/Prime_number
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
frogmelter
Profile Blog Joined April 2009
United States971 Posts
Last Edited: 2012-11-05 04:38:21
November 05 2012 04:36 GMT
#62
On November 05 2012 13:35 obesechicken13 wrote:
Show nested quote +
On November 05 2012 13:31 frogmelter wrote:
On November 05 2012 13:25 obesechicken13 wrote:
1) Code a case to check if it is a prime number to begin with. If it isn't, then enter the loop

If I could do this I'd be a millionaire.


It can find the prime factors of 9,223,372,036,854,775,808 pretty fast [sub 5 seconds].

Lol. I don't know if you're trolling or if you misunderstand the problem. But That number above has only one prime factor: 2.


I'm not trolling.

Since the algorithm divides, it will come up with the answer pretty fast. The factors are 2^63, and every pass will divide it by 2. Meaning the loop only needs to run 63 times.

The problem occurs when you have a huge jump, like the first prime factor is like 6,000,000,000+ or so.

Ok. well you seem to know more than I gave you credit for then.

I'm not sure if it is possible to prove if a(any) number that large is prime in 5 seconds. I just heard from wikipedia that:
Show nested quote +
There is no known useful formula that yields all of the prime numbers and no composites.


http://en.wikipedia.org/wiki/Prime_number


http://en.wikipedia.org/wiki/Miller–Rabin_primality_test

Try that test

And yes, wikipedia is correct. What we are doing is a smarter brute force approach. At best we can try to mitigate the worst case run times, but there are some cases where the run time for the particular algorithm I posted will be O(sqrt(n)/2), which in some cases is still too high
TL+ Member
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
November 05 2012 04:37 GMT
#63
On November 05 2012 13:36 frogmelter wrote:
Show nested quote +
On November 05 2012 13:35 obesechicken13 wrote:
On November 05 2012 13:31 frogmelter wrote:
On November 05 2012 13:25 obesechicken13 wrote:
1) Code a case to check if it is a prime number to begin with. If it isn't, then enter the loop

If I could do this I'd be a millionaire.


It can find the prime factors of 9,223,372,036,854,775,808 pretty fast [sub 5 seconds].

Lol. I don't know if you're trolling or if you misunderstand the problem. But That number above has only one prime factor: 2.


I'm not trolling.

Since the algorithm divides, it will come up with the answer pretty fast. The factors are 2^63, and every pass will divide it by 2. Meaning the loop only needs to run 63 times.

The problem occurs when you have a huge jump, like the first prime factor is like 6,000,000,000+ or so.

Ok. well you seem to know more than I gave you credit for then.

I'm not sure if it is possible to prove if a(any) number that large is prime in 5 seconds. I just heard from wikipedia that:
There is no known useful formula that yields all of the prime numbers and no composites.


http://en.wikipedia.org/wiki/Prime_number


http://en.wikipedia.org/wiki/Miller–Rabin_primality_test

Try that test

No. Good night. I'll do sieve when I feel like it in the future.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
frogmelter
Profile Blog Joined April 2009
United States971 Posts
November 05 2012 04:55 GMT
#64
On November 05 2012 13:37 obesechicken13 wrote:
Show nested quote +
On November 05 2012 13:36 frogmelter wrote:
On November 05 2012 13:35 obesechicken13 wrote:
On November 05 2012 13:31 frogmelter wrote:
On November 05 2012 13:25 obesechicken13 wrote:
1) Code a case to check if it is a prime number to begin with. If it isn't, then enter the loop

If I could do this I'd be a millionaire.


It can find the prime factors of 9,223,372,036,854,775,808 pretty fast [sub 5 seconds].

Lol. I don't know if you're trolling or if you misunderstand the problem. But That number above has only one prime factor: 2.


I'm not trolling.

Since the algorithm divides, it will come up with the answer pretty fast. The factors are 2^63, and every pass will divide it by 2. Meaning the loop only needs to run 63 times.

The problem occurs when you have a huge jump, like the first prime factor is like 6,000,000,000+ or so.

Ok. well you seem to know more than I gave you credit for then.

I'm not sure if it is possible to prove if a(any) number that large is prime in 5 seconds. I just heard from wikipedia that:
There is no known useful formula that yields all of the prime numbers and no composites.


http://en.wikipedia.org/wiki/Prime_number


http://en.wikipedia.org/wiki/Miller–Rabin_primality_test

Try that test

No. Good night. I'll do sieve when I feel like it in the future.


Good night, and good luck
TL+ Member
teamamerica
Profile Blog Joined July 2010
United States958 Posts
November 05 2012 07:45 GMT
#65
Hey can someone tell me if my thought process is right? I'm thinking of how to find if a number is prime given fermats little thm. which states a^p is equivalent to a in mod p (I'm taking a class which covers basic public key exchange).

Knowing that to figure if some p is prime it's just a matter of figuring a^p, and for large p you can use the fast powering algorithm. That splits finding a^p as finding the product to a raised to the binary expansion of p. I.e. a^5 becomes
a^(2^2) *a(2^0). Since this entire set of operations is done mod p, we never exceed p (for overflow - this is how pythons math.pow(x,y,z) works). So we end up with log2 multiplications to perform.

But on thinking about this, why how come you can't just use a=1 and then it would seem that every p is prime o.O...Anyone tell me what obvious part I'm doing wrong/missing?
RIP GOMTV. RIP PROLEAGUE.
mmp
Profile Blog Joined April 2009
United States2130 Posts
Last Edited: 2012-11-05 08:29:41
November 05 2012 08:25 GMT
#66
On November 05 2012 16:45 teamamerica wrote:
Hey can someone tell me if my thought process is right? I'm thinking of how to find if a number is prime given fermats little thm. which states a^p is equivalent to a in mod p (I'm taking a class which covers basic public key exchange).

Knowing that to figure if some p is prime it's just a matter of figuring a^p, and for large p you can use the fast powering algorithm. That splits finding a^p as finding the product to a raised to the binary expansion of p. I.e. a^5 becomes
a^(2^2) *a(2^0). Since this entire set of operations is done mod p, we never exceed p (for overflow - this is how pythons math.pow(x,y,z) works). So we end up with log2 multiplications to perform.

But on thinking about this, why how come you can't just use a=1 and then it would seem that every p is prime o.O...Anyone tell me what obvious part I'm doing wrong/missing?

Fermat's probable prime theorem is probable. You have to repeat the test for various moduli.

Even then, it's ridiculously fast to repeat ~100 times to get good confidence.

Note that Carmichael Numbers break Fermat's Little Theorem, but I believe the density of Carmichael numbers goes down for big numbers, so this can be ignored for applications like RSA.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
teamamerica
Profile Blog Joined July 2010
United States958 Posts
November 05 2012 12:41 GMT
#67
On November 05 2012 17:25 mmp wrote:
Show nested quote +
On November 05 2012 16:45 teamamerica wrote:
Hey can someone tell me if my thought process is right? I'm thinking of how to find if a number is prime given fermats little thm. which states a^p is equivalent to a in mod p (I'm taking a class which covers basic public key exchange).

Knowing that to figure if some p is prime it's just a matter of figuring a^p, and for large p you can use the fast powering algorithm. That splits finding a^p as finding the product to a raised to the binary expansion of p. I.e. a^5 becomes
a^(2^2) *a(2^0). Since this entire set of operations is done mod p, we never exceed p (for overflow - this is how pythons math.pow(x,y,z) works). So we end up with log2 multiplications to perform.

But on thinking about this, why how come you can't just use a=1 and then it would seem that every p is prime o.O...Anyone tell me what obvious part I'm doing wrong/missing?

Fermat's probable prime theorem is probable. You have to repeat the test for various moduli.

Even then, it's ridiculously fast to repeat ~100 times to get good confidence.

Note that Carmichael Numbers break Fermat's Little Theorem, but I believe the density of Carmichael numbers goes down for big numbers, so this can be ignored for applications like RSA.


Oh whoa, I never knew it was probable - also never knew about Carmicheal numbers (or that Fermats thm. failed at all TT). Well at least tomorrow when I ask my teacher some questions I'll look like I've actually been doing the reading!

Anyway, I saw some posts about learning C++ - I'm always an advocate for good books, esp. in languages where it's easy to do stuff the wrong way. So there's
http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
RIP GOMTV. RIP PROLEAGUE.
dakalro
Profile Joined September 2010
Romania525 Posts
November 05 2012 15:24 GMT
#68
On November 04 2012 17:29 spinesheath wrote:
Show nested quote +
On November 04 2012 07:25 Lysenko wrote:
On November 04 2012 04:15 CecilSunkure wrote:
On November 04 2012 02:09 Sawamura wrote:
now if could write some C++ program practice ^_^ hehehe thanks for the practice anyway 5/5

I could do that. I'm thinking of some object oriented C first though. You know, virtualizing some C++ features in C.


I was on my way to a much longer post, but I don't want to get in the way of what you're doing here with a lot of negativity, so I'll just ask. Who learns C today, absent a specific need to write embedded code, modify a UNIX or Linux kernel, or write a driver?

I'm speaking as someone who paid several years of bills as a C programmer, working on both embedded applications and desktop applications. This was, however, 17 years ago, before (as far as I have personally seen, which is why I'm asking) the entire world moved on to C++.



** I mean, I can see doing it out of nostalgia, or because I got a cheap deal on some single-chip-computer development board, but that's about it. Is this a topic of interest for typical, highly-motivated CS students these days? I'm not saying it's bad, I just don't get it.

You learn C to work with the crappy old codebase many companies still have. If you start a new project from scratch, you better have a damn good reason to use C. But if you work on something that uses old code, chances are it uses C.

That's no reason to start with C as your first language though.


I can tell you from 1st hand experience that you would miss your mobile phone functionality if C were to vanish now :D. C is here to stay and it will keep running the backend of a lot of stuff.
nath
Profile Blog Joined May 2010
United States1788 Posts
November 05 2012 16:56 GMT
#69
On November 04 2012 17:29 spinesheath wrote:
Show nested quote +
On November 04 2012 07:25 Lysenko wrote:
On November 04 2012 04:15 CecilSunkure wrote:
On November 04 2012 02:09 Sawamura wrote:
now if could write some C++ program practice ^_^ hehehe thanks for the practice anyway 5/5

I could do that. I'm thinking of some object oriented C first though. You know, virtualizing some C++ features in C.


I was on my way to a much longer post, but I don't want to get in the way of what you're doing here with a lot of negativity, so I'll just ask. Who learns C today, absent a specific need to write embedded code, modify a UNIX or Linux kernel, or write a driver?

I'm speaking as someone who paid several years of bills as a C programmer, working on both embedded applications and desktop applications. This was, however, 17 years ago, before (as far as I have personally seen, which is why I'm asking) the entire world moved on to C++.



** I mean, I can see doing it out of nostalgia, or because I got a cheap deal on some single-chip-computer development board, but that's about it. Is this a topic of interest for typical, highly-motivated CS students these days? I'm not saying it's bad, I just don't get it.

You learn C to work with the crappy old codebase many companies still have. If you start a new project from scratch, you better have a damn good reason to use C. But if you work on something that uses old code, chances are it uses C.

That's no reason to start with C as your first language though.

maybe in germany, in the US old codebases hardly ever use C
Founder of Flow Enterprises, LLC http://flow-enterprises.com/
nath
Profile Blog Joined May 2010
United States1788 Posts
November 05 2012 16:57 GMT
#70
On November 06 2012 00:24 dakalro wrote:
Show nested quote +
On November 04 2012 17:29 spinesheath wrote:
On November 04 2012 07:25 Lysenko wrote:
On November 04 2012 04:15 CecilSunkure wrote:
On November 04 2012 02:09 Sawamura wrote:
now if could write some C++ program practice ^_^ hehehe thanks for the practice anyway 5/5

I could do that. I'm thinking of some object oriented C first though. You know, virtualizing some C++ features in C.


I was on my way to a much longer post, but I don't want to get in the way of what you're doing here with a lot of negativity, so I'll just ask. Who learns C today, absent a specific need to write embedded code, modify a UNIX or Linux kernel, or write a driver?

I'm speaking as someone who paid several years of bills as a C programmer, working on both embedded applications and desktop applications. This was, however, 17 years ago, before (as far as I have personally seen, which is why I'm asking) the entire world moved on to C++.



** I mean, I can see doing it out of nostalgia, or because I got a cheap deal on some single-chip-computer development board, but that's about it. Is this a topic of interest for typical, highly-motivated CS students these days? I'm not saying it's bad, I just don't get it.

You learn C to work with the crappy old codebase many companies still have. If you start a new project from scratch, you better have a damn good reason to use C. But if you work on something that uses old code, chances are it uses C.

That's no reason to start with C as your first language though.


I can tell you from 1st hand experience that you would miss your mobile phone functionality if C were to vanish now :D. C is here to stay and it will keep running the backend of a lot of stuff.

very true
Founder of Flow Enterprises, LLC http://flow-enterprises.com/
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
November 05 2012 18:31 GMT
#71
On November 06 2012 01:56 nath wrote:
Show nested quote +
On November 04 2012 17:29 spinesheath wrote:
On November 04 2012 07:25 Lysenko wrote:
On November 04 2012 04:15 CecilSunkure wrote:
On November 04 2012 02:09 Sawamura wrote:
now if could write some C++ program practice ^_^ hehehe thanks for the practice anyway 5/5

I could do that. I'm thinking of some object oriented C first though. You know, virtualizing some C++ features in C.


I was on my way to a much longer post, but I don't want to get in the way of what you're doing here with a lot of negativity, so I'll just ask. Who learns C today, absent a specific need to write embedded code, modify a UNIX or Linux kernel, or write a driver?

I'm speaking as someone who paid several years of bills as a C programmer, working on both embedded applications and desktop applications. This was, however, 17 years ago, before (as far as I have personally seen, which is why I'm asking) the entire world moved on to C++.



** I mean, I can see doing it out of nostalgia, or because I got a cheap deal on some single-chip-computer development board, but that's about it. Is this a topic of interest for typical, highly-motivated CS students these days? I'm not saying it's bad, I just don't get it.

You learn C to work with the crappy old codebase many companies still have. If you start a new project from scratch, you better have a damn good reason to use C. But if you work on something that uses old code, chances are it uses C.

That's no reason to start with C as your first language though.

maybe in germany, in the US old codebases hardly ever use C


As an american engineer who codes entirely in C, I disagree.

Also, I help build a corporate C compiler, ask me anything about those silly optimizations you want, though, under the hood its really just black magic.
Any sufficiently advanced technology is indistinguishable from magic
Lysenko
Profile Blog Joined April 2010
Iceland2128 Posts
November 05 2012 19:50 GMT
#72
On November 06 2012 00:24 dakalro wrote:
Show nested quote +
On November 04 2012 17:29 spinesheath wrote:
On November 04 2012 07:25 Lysenko wrote:
On November 04 2012 04:15 CecilSunkure wrote:
On November 04 2012 02:09 Sawamura wrote:
now if could write some C++ program practice ^_^ hehehe thanks for the practice anyway 5/5

I could do that. I'm thinking of some object oriented C first though. You know, virtualizing some C++ features in C.


I was on my way to a much longer post, but I don't want to get in the way of what you're doing here with a lot of negativity, so I'll just ask. Who learns C today, absent a specific need to write embedded code, modify a UNIX or Linux kernel, or write a driver?

I'm speaking as someone who paid several years of bills as a C programmer, working on both embedded applications and desktop applications. This was, however, 17 years ago, before (as far as I have personally seen, which is why I'm asking) the entire world moved on to C++.



** I mean, I can see doing it out of nostalgia, or because I got a cheap deal on some single-chip-computer development board, but that's about it. Is this a topic of interest for typical, highly-motivated CS students these days? I'm not saying it's bad, I just don't get it.

You learn C to work with the crappy old codebase many companies still have. If you start a new project from scratch, you better have a damn good reason to use C. But if you work on something that uses old code, chances are it uses C.

That's no reason to start with C as your first language though.


I can tell you from 1st hand experience that you would miss your mobile phone functionality if C were to vanish now :D. C is here to stay and it will keep running the backend of a lot of stuff.


To all the folks who keep bringing up embedded applications in response to my comments about C largely not being used today (and the comments on my comments) please note that embedded applications are one of the specific examples (among others) I mentioned that would benefit from learning C.
http://en.wikipedia.org/wiki/Lysenkoism
]343[
Profile Blog Joined May 2008
United States10328 Posts
Last Edited: 2012-11-05 22:04:44
November 05 2012 22:02 GMT
#73
bros bros there exist polynomial-time primality tests like http://en.wikipedia.org/wiki/AKS_primality_test

factoring, on the other hand, is not known to be in P (which is why RSA hasn't been broken, yet)

(in fact a lot of cryptography relies on stuff which is not proven, such as: "factoring is hard"; "discrete log is hard"; and "there exists a pseudorandom number generator" [which is true if "discrete log is hard"])

On November 05 2012 17:25 mmp wrote:
Fermat's probable prime theorem is probable. You have to repeat the test for various moduli.


hmm, I guess it's probabilistic if you choose random guys a and take a^n-1... but yeah the converse of Fermat's Little Theorem is not necessarily true.
Writer
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
November 06 2012 03:48 GMT
#74
On November 06 2012 07:02 ]343[ wrote:
bros bros there exist polynomial-time primality tests like http://en.wikipedia.org/wiki/AKS_primality_test

Wiki says the original test had a worst case of Õ(log^12(n))
So that's like log(log(log(log...log(n)))))...)))
12 iterated logarithms. I had to go on wolfram to brush up on iterated logarithms. In that case checking for primes is pretty damn fast.

The Euler problem in question though was considered the third easiest question on the site. I highly doubt everyone who solved the problem knew AKS primality test considering the next few problems look really easy in comparison.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
November 08 2012 13:13 GMT
#75
my solution to #5 used a simple bubble sort :D
+ Show Spoiler +

#include <stdio.h> /* printf */

/* Swap the contents of two pointers. Do not modify the prototype.
Use your function from PointerPractice_3 here. */
void SwapInts(int *a,int *b )
{
/* Place your code here. Modify these lines. */
int temp = *a;
*a = *b;
*b = temp;
}

/* Print contents of an array. Do not modify this function. */
void PrintArray( const int* array, const int size )
{
int i;
for(i = 0; i < size; ++i, ++array)
{
if(i != size - 1)
printf( "%d, ", *array);
else
printf( "%d\n", *array);
}
}

int main( void )
{
/* Create array on the stack. */
int stackArray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

/* Get size of array. stackArray can be treated as pointer to first element. */
int arraySize = sizeof( stackArray ) / sizeof( *stackArray );

/* Can treat name of an array as pointer to first element. */
PrintArray( stackArray, arraySize );

/* Reverse the array here */
/**/
/**/
/**/
int i, j;
for (i = (arraySize - 1); i > 0; i--)
{
for (j = 1; j <= i; j++)
{
if (stackArray[j-1] < stackArray[j])
{
SwapInts(&stackArray[j-1], &stackArray[j]);
}
}
}

PrintArray( stackArray, arraySize );

/* Correct output:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 */

return 0;
}
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
SeeDLiNg
Profile Joined January 2010
United States690 Posts
December 19 2012 18:04 GMT
#76
So, I know what it's finding... But I don't really know how it's finding it...

int arraySize = sizeof( stackArray ) / sizeof( *stackArray );

Can someone break down how exactly this is finding the arraySize for me please?
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 19 2012 21:05 GMT
#77
On December 20 2012 03:04 SeeDLiNg wrote:
So, I know what it's finding... But I don't really know how it's finding it...

int arraySize = sizeof( stackArray ) / sizeof( *stackArray );

Can someone break down how exactly this is finding the arraySize for me please?

Sure!

So with an array on the stack C actually knows the number of elements in the array. So when you do sizeof( stackArray ) the stackArray has not yet implicitly decayed into a pointer, and is actually being treated as a proper array. C multiplies the size of a single element in the array by the number of arrays, and this returns the number of bytes the entire array takes up within memory.

So then sizeof( *stackArray ) is implicitly decaying the stackArray identifier into a pointer and then dereferencing it. The value of *stackArray is that of the first element in the array, since an array's identifier can always be implicitly decayed into a pointer to the first element. So then the size of the first element is 4 bytes: the size of the integer first element.

Then you divide the size of bytes in total by the size in bytes of the first element to get the number of elements total.
Prev 1 2 3 4 All
Please log in or register to reply.
Live Events Refresh
StarCraft2.fi
17:00
15V Cup / Groups Day 2
starcraft2fi 63
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko534
mouzHeroMarine 421
gerald23 157
Livibee 94
BRAT_OK 65
MindelVK 20
StarCraft: Brood War
Calm 4381
Larva 734
Mini 398
Rush 322
firebathero 279
hero 88
soO 48
Mong 37
Terrorterran 29
Sacsri 14
[ Show more ]
Movie 14
yabsab 12
HiyA 7
Dota 2
Gorgc5769
qojqva3625
Dendi952
420jenkins356
League of Legends
rGuardiaN41
Counter-Strike
fl0m10418
zeus645
chrisJcsgo27
pashabiceps20
Other Games
FrodaN2184
B2W.Neo1209
hiko835
Beastyqt591
RotterdaM203
Hui .155
KnowMe135
ArmadaUGS132
Mew2King119
QueenE102
Trikslyr67
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• Reevou 21
• Kozan
• LaughNgamezSOOP
• AfreecaTV YouTube
• sooper7s
• intothetv
• Migwel
• IndyKCrew
StarCraft: Brood War
• FirePhoenix8
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2647
• WagamamaTV597
• Noizen44
League of Legends
• Nemesis3400
• TFBlade911
Other Games
• Shiphtur174
Upcoming Events
PiGosaur Monday
7h 18m
Wardi Open
18h 18m
StarCraft2.fi
23h 18m
Replay Cast
1d 6h
The PondCast
1d 16h
Replay Cast
2 days
Korean StarCraft League
3 days
CranKy Ducklings
3 days
SC Evo League
3 days
BSL 21
4 days
Sziky vs OyAji
Gypsy vs eOnzErG
[ Show More ]
OSC
4 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
4 days
BSL 21
5 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
5 days
Wardi Open
5 days
StarCraft2.fi
5 days
Replay Cast
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-28
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.