|
|
[tutorial] Basics Of C Programming - Part 2 | ||
Discussion by dhanesh with 21 Replies.
Last Update: October 17, 2008, 10:36 pm | |||
![]() |
|
|
Operators & Expressions in C
Introduction
- In c the variable, arrays or function references are combined with operators to form expressions.
- The data items that the operators act upon are called operands.
- Some operators require two operands will others require just a single operand to act upon.
- Arithmetic Operators
- Unary Operators
- Relational and Logical Operators
- Assignment Operators
- Conditional Operators
- + : Addition
- : subtraction
- * : Multiplication
- / : Division
- % : Modulus
- The operands must represent numeric values
- % : Both operands must be integer and second one nonzero.
- / : Second operand must be a Nonzero.
- Both operands are integers then referred to as integer division
- Operation is carried by two floating values then Floating point division.
- If one integer and the other float then the result will be floating quotient.
Syntax ( Data type) Expression
Eg. ((int)
Unary Operator:
- They act upon a single operand to produce a new value.
- Increment Operator
Eg: ++a, a++
- Decrement Operator
Eg. : --a, a--.
- sizeof : returns the size of the operand in terms of bytes. And is always preceded by its operand.
Relational and Logical Operator:
Relational Operators :
- <= : Less than or equal to
- >= : Greater than or equal to
- > : Greater than
- < : Less than
- == : Equal to
- != : Not Equal to
- && - and : Both the conditions should hold true
- || - or : Either one of the condition should hold true for the action to be performed.
- They are used to form an assignment expression
- It would assign a value of an expression to a identifier.
- =
- +=
- -=
- *=
- /=
- %=
- Used for carrying out conditional operations – ( ? : )
- Syntax : Expression 1 ? Expression 2 : Expression 3
ans= (i<=10) ? 0 : 1
Yeap, well that wraps up the Conditional Operators topic. As suggested, i would post some examples of code later on, but till then you could go through these basic guidelines and perfect them. Hope this helped
Regards
Dhanesh.
Alright, that did make a great Part II, and you didn't screw up any code this time either! Good work, but you missed out some things (Of course you can't teach C Prog. in 2 parts
Honestly, you should be adding some examples and some assignments too, as a good tutor!!!
As for Part 3 .. Its all yours, really .. I havent started yet .. so whenever you get time .. go on and complete whatever i have missed out. Its not easy to complete C in 2 parts true, so i hope you will add up a few pointers for us then
Thankx for your comments.
Regards
Dhanesh.
Long time no see, digital brother. <LOL
Wow I am just amazed at how much you guys are literate in computer programming languages. For me, it's HTML and I only know the basics. Well, it's kinda sad but I guess it can hold out for a little time being while I go try to learn PHP.
Can someone answer my question:
How can you benefit from being literate in C programming and C++?? What about C++ Visuals? Is that another programming language too?
By the way, wonderful job there, Dhanesh. Kudos for you.
Aha .. the Hobbes of asta
QUOTE (cyborgxxi)
Can someone answer my question:
How can you benefit from being literate in C programming and C++?? What about C++ Visuals? Is that another programming language too?
Link: view Post: 83715
I think the best people to answer this would be people who are INTO programming. But lets see, by learning C / C++ which are the foundation of any programming languages today, you would be able to design/program applications flexibly. Visual C++ is a form of basic command C/C++, just with a pretty GUI and with the title of M$, i have seen people who prefer the basic C/C++ more to the Visual C++. One major difference would be the syntax, Different programming languages have different syntax, but its easy to cope up when you are fluent with 1 basic language.
I love to work on Visual Basic, and to be honest, i have to be changing that, cause tho VB might seem easy with GUI and stuff, its not so flexible as command C/C++ ..Hope you get the basic point .. Anyone else who can elaborate on this is welcome
Hope you see more of you around Hobbes ... lol
Regards
Dhanesh.
QUOTE
Honestly, you should be adding some examplesI agree.
Mainle, I see what ++i is (it changes i to i+1).
I would like to know what += means. if a=-1, += applied to a makes it change to -2 or to 0 ?
I've been studying Visual Basic for the past few weeks now as a course in school. It's getting a little more complicated now that i've moved up to ifs and elses. Some of the operators i see used in C (as you have portrayed) is really similar to that of Visual Basic, one difference i can point out though, is how to make equations equal, that is using the double equal sign (==). It reminds me of back when i was studying a little php. They say that Visual Basic is a good base before moving on to other languages such as C or C pluses, it doesn't seem so at first glance, and if you know me, I'm not a very good reading learner
Going out of the topic for a moment. The book we're using in our Visual Basic course describes something about pseudocode. Where you actually incorporate understandable English language as code. A friend told me it is just a form of "laying out" your code into more understandable parts. But I'm wondering if pseudocode actually works as a language itself?
1)First you didn't differntiate between a++ and ++a. May be you have a plan of explaining it later.
2) You have left out bitwise operators completely. (Operators like XOR-^ , OR- | , AND - & , NOT - ~ ). In fact along with the assignment operators you've mentioned, the following also hold good.
|=,
&=,
^=.
3)Also, there are bitshift operators. Bitwise left shift (<<) and bitwise right shift(>>) operators whih help in doing bitshifting operations.
Once again I repeat I'm not sure if you have plans of covering these in your next part. But if you didn't have such plans, you can include these in your next part of the tutorial
QUOTE (Chesso)
It looks like a great piece of information to me, Iv'e done DLL's and things in C++ and still didn't know some of that
Link: view Post: 89753
May be bacause you never needed BITWISE operators... They are very much useful in embedded system programming and system programming.
For high level codes, BITWISE operators may not be necessary. (I've never done any DLL's. So ain't sure if you do BIT operations there... All I know about DLL is it stands for Dinamic Link Libraries. Atleast thet's what I think it is
[PS: Sorry for late response. Didn't come online for a long time as I was caught up with series of unfortunate events. Finally I'm free!!!
QUOTE (yordan)
I agree.
Mainle, I see what ++i is (it changes i to i+1).
I would like to know what += means. if a=-1, += applied to a makes it change to -2 or to 0 ?
Link: view Post: 89645
Here is an example:
a = 10;
a += 1;
(a==11);
a = 0;
a += -1;
(a==-1);
a = 5;
a += -3;
(a==2);
So a += b; is the same as writing a = a + b;, just a simpler syntax.
QUOTE (bluefish)
Here is an example:
a = 10;
a += 1;
(a==11);
a = 0;
a += -1;
(a==-1);
a = 5;
a += -3;
(a==2);
So a += b; is the same as writing a = a + b;, just a simpler syntax.
Link: view Post: 94789
OK, thanks for the reply. I learned something today, now I know what "+=" means.
QUOTE (Chesso)
I actually didn't know what it meant either, but I don't think I have ever needed to use it, but then again Iv'e only seen it used rarely.
Link: view Post: 94965
rarely is already a lot. I never saw thins += thing until today, and I don't even mind seeing somebody using it. Nevertheless, from a philosophical point of view, knowledge is supposed to be a good thing, even for (probably) useless things
All in all a good tutorial, and i await the next part with great anticipation
I think i'm gonna learn a lot here.
Long time no see, digital brother. <LOL
Wow I am just amazed at how much you guys are literate in computer programming languages. For me, it's HTML and I only know the basics. Well, it's kinda sad but I guess it can hold out for a little time being while I go try to learn PHP.
Can someone answer my question:
How can you benefit from being literate in C programming and C++?? What about C++ Visuals? Is that another programming language too?
As for the last one you mentioned, I think you mean Visual C++ and variants, which are Microsoft products (Microsoft Visual C++).
QUOTE (Chesso)
C was a non object oriented programming language, C++ is just a well, more updated version of C that includes more modern standards including OOP.As for the last one you mentioned, I think you mean Visual C++ and variants, which are Microsoft products (Microsoft Visual C++).
Link: view Post: 109003
C and C++ are general purpose programming languages, if you can write c or c++ you can virtually do anything, i suggest you stick with console applications as you start, you can do graphical stuff later when you'd mastered the language very well.
Although C++ looks like C, it's quite a different language and it was rewritten from scratch with C compatibility in mind but with so many enhancements, the most visible improvement with C++ is that it is object oriented, this is a different programming paradigme from procedural C.
I would like to emphasise the fact that the C WASN'T, the C language still IS !! i personnally do a lot of work in this language wich i find to be a very powerfull tool of work, although i am familiar with C++i still write C daily, however as a beginner you can start C++ directly, most of us still use C because one way or another it's the language we master the best.
Visual C++, is just an integrated development environment (IDE), it only runs in microsoft windows, this is an inferior software platform, if you want to do some real development you should use a higher grade system such as GNU/Linux or FreeBSD.
Similar Topics:
Programming With Coffee
What Shall I Learn First In Program...
How To Learn A Programming Language
Writing ISRs (Interrupt Service Routines) Interrupt Service Routines (6)
|
(10) C++: Basic Classes classes, objects, access labels, members, inline functions
|
HOME ![Quickly Post to [tutorial] Basics Of C Programming - Part 2 w/o signup](http://xisto.cachefly.net/asta/template/x/html//images/reply.png)

![email your friend about [tutorial] Basics Of C Programming - Part 2](http://xisto.cachefly.net/asta/template/x/html//images/email.png)




