Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

im new with C can someone help me with that?

Why don't you just run it and find out? We're not here to do your homework.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites

You need to initlize the variable a with an integer, which means add a value. a as it stands is uninitilized and has no value. You can therefore not use it.

 

Also please add return 0 at the end of every c main to end the program. There are other ways but this is best practice. It just shows that wenn your program ends with 0, than it ran successfully.

Link to post
Share on other sites
29 minutes ago, Teddy07 said:

You need to initlize the number  a which means add a value. a as it stands is uninitilized and has no value. You can therefore not use it.

 

Also please add return 0 at the end of every c main to end the program. There are other ways but this is best practice. It just shows that wenn your program ends with 0, than it ran successfully.

You can have a main function use void but imo you're right it is better to always return an integer because technically it's an exit code.

 

As for an uninitialized value... Well I mean technically you can use it; it gets put on the stack. If you ask to do printf("%d", a) then it's going to just read whatever bytes happen to be there, which could be anything. I believe it's important to make the distinction that you definitely can use variables that haven't been initialized in C. If only because it can get you into trouble if you don't initialize them before using them.

Link to post
Share on other sites
3 minutes ago, Sakuriru said:

just read whatever eight bits happen to be there, which could be anything

I assume C tries to interpret the unitilized bit value at the location as an integer? Because a string value would be an error

Link to post
Share on other sites

int a;   defines a variable called a , but doesn't assign any value to it.   Some C compilers will auto initialize it with value 0, others won't, so when reading the value you'll simply read whatever was in computer ram where the a variable was put.

 

printf prints variables according to the pattern you give it ... %d means a decimal number,  so it will print whatever is stored in the 4 or 8 bytes the variable a reserved in memory (int size depends on compiler and architecture, could be 2 bytes on 16 bit microcontrollers, but usually it's 32 bits or 4 bytes)

 

the function doesn't return anything, and doesn't have to, because you used the void keyword in front of the function name.

Link to post
Share on other sites
3 hours ago, Teddy07 said:

I assume C tries to interpret the unitilized bit value at the location as an integer?

Yep

3 hours ago, Teddy07 said:

Because a string value would be an error

I don't thinks so. A string in C is just a pointer.

#include <stdio.h>

int main(){    
  int a = 0x6c6c6568;
  int b = 0x6f77206f;
  int c = 0x00646c72;
  printf("\n%s", (char*)&a);

  int data[] = {0x6c6c6568, 0x6f77206f, 0x00646c72};
  printf("\n%s", (char*)&data);
  
  printf("\n%s", "hello world");
  
  return 0;
}

 

 

ಠ_ಠ  if i said something stupid please let me know

Link to post
Share on other sites
23 minutes ago, shadow_ray said:

Yep

I don't thinks so. A string in C is just a pointer.



#include <stdio.h>

int main(){    
  int a = 0x6c6c6568;
  int b = 0x6f77206f;
  int c = 0x00646c72;
  printf("\n%s", (char*)&a);

  int data[] = {0x6c6c6568, 0x6f77206f, 0x00646c72};
  printf("\n%s", (char*)&data);
  
  printf("\n%s", "hello world");
  
  return 0;
}

 

 

thanks man. Always good to keep learning. I was too lazy to test

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×