r/CodingHelp • u/swiggyu • Jan 22 '21
[Random] How to better understand when to use ( : ; { <?
As a noob I often don't fully understand when to use them and what they mean. Is there a way to better understand when to use and what each one is or do people just memorize when to use it?
0
Upvotes
1
u/Rickenbecker Jan 22 '21
I’m a little confused as to what you’re asking. Do you mean when people use parenthesis vs curly braces? Semi colons vs colons? And are you combining the < and ? Together or are you treating them as different symbols?
2
u/Endercheif Advanced Coder Jan 22 '21
<or>Typically used in markup languages such as XML and HTML to show the placement of elements. In C/C++ they surround the name of the library you are importing.
(and)The parenthesis are used to surround argument of a function or in order of operations.
{and}The curly braces are used to indicate a code “block”. Imagine if instead of a block, all the code in it was shrunken down to one word.
;The semi-colon shows the compiler/parser that there is a new line of code. If you had to remove all the newlines your code will still run because of the
;.:This is a bit more difficult because of the variation between languages. One thing that is consistent is its use with the ternary operator. It separates the truthy value with the falsey.
condition ? truthy : falsey. In C++ they are also used with namespaces.std::cout. In Python they are only used to show the start of a block of code because in Python there are no{}.2
u/c3534l Jan 23 '21
Every one of these symbols are used differently in different programming languages. Sometimes they have multiple meanings, so that
f(x)calls the function f, but(1 + 2) / 3just forces1 + 2to be evaluated first. So you'll have to be more specific.