Free Essay

C++ Manual

In:

Submitted By boomba118
Words 1168
Pages 5
Bài 1 : Cấu Trúc Của Một Chương Trình C++
Có lẽ một trong những cách tốt nhất để bắt đầu học một ngôn ngữ lập trình là bằng một chương trình. Vậy đây là chương trình đầu tiên của chúng ta :
|// my first program in C++ |Hello World! |
| | |
|#include | |
| | |
|int main () | |
|{ | |
|cout >=, = |Lớn hơn hoặc bằng |
|< = |Nhỏ hơn hoặc bằng |

Ví dụ:
|(7 == 5) |sẽ trả giá trị false |

|(6 >= 6) |sẽ trả giá trị true |

tất nhiên thay vì sử dụng các số, chúng ta có thể sử dụng bất cứ biểu thức nào. Cho a=2, b=3 và c=6
|(a*b >= c) |sẽ trả giá trị true. |
|(b+4 < a*c) |sẽ trả giá trị false |

Cần chú ý rằng = (một dấu bằng) lf hoàn toàn khác với == (hai dấu bằng). Dấu đầu tiên là một toán tử gán ( gán giá trị của biểu thức bên phải cho biến ở bên trái) và dấu còn lại (==) là một toán tử quan hệ nhằm so sánh xem hai biểu thức có bằng nhau hay không. |Trong nhiều trình dịch có trước chuẩn ANSI-C++ cũng như trong ngôn ngữ C, các toán tử quan hệ không trả về giá trị logic |
|true hoặc false mà trả về giá trị int với 0 tương ứng với false còn giá trị khác 0 (thường là 1) thì tương ứng với true. |

Các toán tử logic ( !, &&, || ). Toán tử ! tương đương với toán tử logic NOT, nó chỉ có một đối số ở phía bên phải và việc duy nhất mà nó làm là đổi ngược giá trị của đối số từ true sang false hoặc ngược lại. Ví dụ:
|!(5 == 5) |trả về false vì biểu thức bên phải (5 == 5) có giá trịtrue. |
|!(6 6)) trả về true ( true || false ).
Toán tử điều kiện ( ? ). Toán tử điều kiện tính toán một biểu thức và trả về một giá trị khác tuỳ thuộc vào biểu thức đó là đúng hay sai. Cấu trúc của nó như sau: condition ? result1 : result2 Nếu condition là true thì giá trị trả về sẽ là result1, nếu không giá trị trả về là result2.
|7==5 ? 4 : 3 |trả về 3 vì 7 không bằng 5. |
|7==5+2 ? 4 : 3 |trả về 4 vì 7 bằng 5+2. |
|5>3 ? a : b |trả về a, vì 5 lớn hơn 3. |
|a>b ? a : b |trả về giá trị lớn hơn, a hoặc b. |

Các toán tử thao tác bit ( &, |, ^, ~, ). Các toán tử thao tác bit thay đổi các bit biểu diễn một biến, có nghĩa là thay đổi biểu diễn nhị phân của chúng
|toán tử |asm |Mô tả |
|& |AND |Logical AND |
|| |OR |Logical OR |
|^ |XOR |Logical exclusive OR |
|~ |NOT |Đảo ngược bit |
|> |SHR |Dịch bit sang phải |

Các toán tử chuyển đổi kiểu Các toán tử chuyển đổi kiểu cho phép bạn chuyển đổi dữ liệu từ kiểu này sang kiểu khác. Có vài cách để làm việc này trong C++, cách cơ bản nhất được thừa kế từ ngôn ngữ C là đặt trước biểu thức cần chuyển đổi tên kiểu dữ liệu được bọc trong cặp ngoặc đơn (), ví dụ: int i; float f = 3.14; i = (int) f; Đoạn mã trên chuyển số thập phân 3.14 sang một số nguyên (3). Ở đây, toán tử chuyển đổi kiểu là (int). Một cách khác để làm điều này trong C++ là sử dụng các constructors (ở một số sách thuật ngữ này được dịch là cấu tử nhưng tôi thấy nó có vẻ không xuôi tai lắm) thay vì dùng các toán tử : đặt trước biểu thức cần chuyển đổi kiểu tên kiểu mới và bao bọc biểu thức giữa một cặp ngoặc đơn. i = int ( f ); Cả hai cách chuyển đổi kiểu đều hợp lệ trong C++. Thêm vào đó ANSI-C++ còn có những toán tử chuyển đổi kiểu mới đặc trưng cho lập trình hướng đối tượng. sizeof() Toán tử này có một tham số, đó có thể là một kiểu dữ liệu hay là một biến và trả về kích cỡ bằng byte của kiểu hay đối tượng đó. a = sizeof (char); a sẽ mang giá trị 1 vì kiểu char luôn có kích cỡ 1 byte trên mọi hệ thống. Giá trị trả về của sizeof là một hằng số vì vậy nó luôn luôn được tính trước khi chương trình thực hiện. Các toán tử khác Trong C++ còn có một số các toán tử khác, như các toán tử liên quan đến con trỏ hay lập trình hướng đối tượng. Chúng sẽ được nói đến cụ thể trong các phần tương ứng.

Thứ tự ưu tiên của các toán tử

Khi viết các biểu thức phức tạp với nhiều toán hạng các bạn có thể tự hỏi toán hạng nào được tính trước, toán hạng nào được tính sau. Ví dụ như trong biểu thức sau: a = 5 + 7 % 2 có thể có hai cách hiểu sau: a = 5 + (7 % 2) với kết quả là 6, hoặc a = (5 + 7) % 2 với kết quả là 0
Câu trả lời đúng là biểu thức đầu tiên. Vì nguyên nhân nói trên, ngôn ngữ C++ đã thiết lập một thứ tự ưu tiên giữa các toán tử, không chỉ riêng các toán tử số học mà tất cả các toán tử có thể xuất hiện trong C++. Thứ tự ưu tiên của chúng được liệt kê trong bảng sau theo thứ tự từ cao xuống thấp. |Thứ tự |Toán tử |Mô tả |Associativity |
|1 |:: |scope |Trái |
|2 |() [ ] -> . sizeof | |Trái |
|3 |++ -- |tăng/giảm |Phải |
| |~ |Đảo ngược bit | |
| |! |NOT | |
| |& * |Toán tử con trỏ | |
| |(type) |Chuyển đổi kiểu | |
| |+ - |Dương hoặc âm | |
|4 |* / % |Toán tử số học |Trái |
|5 |+ - |Toán tử số học |Trái |
|6 |> |Dịch bit |Trái |
|7 |< >= |Toán tử quan hệ |Trái |
|8 |== != |Toán tử quan hệ |Trái |
|9 |& ^ | |Toán tử thao tác bit |Trái |
|10 |&& || |Toán tử logic |Trái |
|11 |?: |Toán tử điều kiện |Phải |
|12 |= += -= *= /= %= |Toán tử gán |Phải |
| |>>=

Similar Documents

Premium Essay

Mundra

...|Sunita Mundra |Contact | | | | |MBA – Finance ▪ Date of birth : 00 July 1900 |Tel : +91 93467 00281 | | |e-mail : sunitamundra@ymail.com | | | | | | |Address | | | |Sri Ramachandra Résidency, Tanuku – 00000 , Andhra pradesh | | ...

Words: 321 - Pages: 2

Free Essay

Gunda Resume

...CURRICULUM VITAE YOGEESH N S Ph No : 09844616594 Email : yogeesh.6167@gmail.com OBJECTIVE: To build a career in an organization where I can enhance my skills and grow in conjunction with the organizations’ objectives ACADEMIC DETAILS: Bachelor of Engineering in Electrical and Electronics from University BDT College of Engineering Davanagere, Kuvempu University, Karnataka. Examination | Name of Institution | University/Board | Year of passing | %Age | BE | U.B.D.T.C.E Davangere | Kuvempu | 2010 | 68.94% | DIPLOMA | D.A.C.G.Govt PolytechnicChickmagalore | K.T.B | 2007 | 68.89% | S.S.L.C | S U S J H School Bukkambudhi | K.S.E.E.Board | 2004 | 76.16% | TECHNICAL SKILLS: Programming Language : C,Manual testing and SQL. Assembly Language : Microprocessor 8085 Other programming Languages : PSPICE and MATLAB. Operating Systems : Windows 98/XP PERSONAL SKILLS: * Ability to work independently and as a team. * Dedicated, Hardworking nature and adaptable to all situations. PROJECT PROFILE: * I have done a project on“ MICROCONTROLLER BASED ANNUNCIATION SYSTEM” * I have done a project on “ TIDAL POWER PLANT ” Extra Curricular activites: * Forum President at final year Electrical & Electronics Engg in UBDTCE Davangere PERSONAL PROFILE: Date of Birth : 13-05-1989 Father’s name : Sannamalleshappa.N.B ...

Words: 255 - Pages: 2

Premium Essay

Object Oriented Analysis and Design

...tools include a forms designer for building GUI applications, web designer, class designer, and database schema designer. It accepts plug-ins that enhance the functionality at almost every level—including adding support for source-control systems (like Subversion) and adding new toolsets like editors and visual designers for domain-specific languages or toolsets for other aspects of the software development lifecycle (like the Team Foundation Server client: Team Explorer). Visual Studio supports different programming languages and allows the code editor and debugger to support (to varying degrees) nearly any programming language, provided a language-specific service exists. Built-in languages include C,[5] C++ and C++/CLI (via Visual C++), VB.NET (via Visual Basic .NET), C# (via Visual C#), and F# (as of Visual Studio 2010[6]). Support for other languages such as M, Python, and...

Words: 1330 - Pages: 6

Free Essay

Advantages of Phase Modulation

...Python Reference Manual Release 2.3.3 Guido van Rossum Fred L. Drake, Jr., editor December 19, 2003 PythonLabs Email: docs@python.org Copyright c 2001, 2002, 2003 Python Software Foundation. All rights reserved. Copyright c 2000 BeOpen.com. All rights reserved. Copyright c 1995-2000 Corporation for National Research Initiatives. All rights reserved. Copyright c 1991-1995 Stichting Mathematisch Centrum. All rights reserved. See the end of this document for complete license and permissions information. Abstract Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for rapid application development, as well as for use as a scripting or glue language to connect existing components together. Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. This reference manual describes the syntax and “core semantics” of the language. It is terse, but attempts to be exact and complete. The semantics of non-essential built-in object types and of the built-in functions and modules are described in the Python...

Words: 14272 - Pages: 58

Free Essay

Report in C++

...language. As its name suggests, simula was designed for doing simulations, and the needs of that domain provided the framework for many of the features of object-oriented languages today. C with classes which as the name implies was meant to be a superset of the c language, His language included classes, basic inheritance, inlining, default functions arguments and strong type checking in addition to all the features of the c language. Cfront was the original compiler for c++ from around 1983, which coverted c++ to c. The preprocessor did not understand all of the language and much of the code was written via translations. Cfront had a complete parser, built symbol tables, and built tree for each class, and functions Cfront was based on CPre (C with classes compiler, which was started in 1979) The ++ operator in the C language is an operator for incrementing a variable, which gives some insight into how Stroustrup regarded the language The c++ programming language was the first book to describe the c++ programming language, written by the language’s creator Bjarne stroustrup, and first published in October 1985, in the absence of an official standard, the book served for several years as the de facto documentation for the evolving c++ language until the release of the ISO/IEC 14882:1998 Turbo C++ added a plethora of additional libraries which would have a...

Words: 593 - Pages: 3

Free Essay

C++ Language

...cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain corrections and changes The C++ Language Tutorial This document and its content is copyright of cplusplus.com © cplusplus.com, 2008. All rights reserved. Any redistribution or reproduction of part or all of the content in any form is prohibited other than to print a personal copy of the entire document or download it to a local hard disk, without modifying its content in any way (including, but not limited to, this copyright notice). You may not, except with express written permission from cplusplus.com, distribute the content of this document. Nor may you transmit it or store it in any other website or other form of electronic retrieval system. 2 © cplusplus.com 2008. All rights reserved The C++ Language Tutorial Table of contents Table of contents ...............................................................................................................................3 Introduction ......................................................................................................................................5 Instructions for use ................................................................................................................................... 5 Basics of C++ .............................................................

Words: 798 - Pages: 4

Free Essay

Pt1420 Unit 1 Research Ass 1

...| Exploring Programming Language | Unit 1 Research Assignment 1 | | | 5/3/2014 | PT1420 | The five most popular programming languages in the 1970’s were: 1970: Pascal 1972: C 1972: Smalltalk 1972: Prolog 1973: SQL Pascal The Pascal programming language was developed by Niklaus Wirth. It was created in 1968 but it wasn’t published until 1970. It was developed to provide the features other programming languages didn’t offer at that time. His main reason for developing Pascal was efficiently implement and run, to allow for the development of structured and well organized programs, and to serve as a tool to teach the important concepts of computer programming. The program was named after a mathematician named Blaise Pascal. It was used as the primary language in the Apple Lisa and for the Mac in the early years of the computer. SQL SQL, which is short for, Structured Query Language, was designed by an IBM research center in 1974-1975. The Oracle Corporation introduced it as a commercial database system in 1979, the first time it was introduced. It has been a favorite query language for the use of database management systems for the microcomputer and mainframes, but is being supported by the PC database. C C was created at the Bell Laboratory in 1972 by Dennis Ritchie. It was created for the purpose in designing UNIX. Prolog Was created from 1971-1973 and was distributed in 1974-1975. It was created not as a programming language on purpose but...

Words: 988 - Pages: 4

Free Essay

C Language

...UNIT 1 NOTES Digital Computer A digital computer is an electronic computing machine that uses the binary digits (bits) 0 and 1 to represent all forms of information internally in digital form. Every computer has a set of instructions that define the basic functions it can perform. Sequences of these instructions. Component of Digital Computer: (1)CPU: The Central Processing Unit (CPU) or the processor is the portion of a computer system that carries out the instructions of a Computer, and is the primary element carrying out the computer's functions. This term has been in use in the computer industry at least since the early 1960s . The form, design and implementation of CPUs have changed dramatically since the earliest examples, but their fundamental operation remains much the same. (2)ALU: an arithmetic logic unit (ALU) is a Digital computer that performs arthimatic and logical operations. The ALU is a fundamental building block of the central processing unit(CPU) of a computer, and even the simplest microprocessor contain one for purposes such as maintaining timers. The processors found inside modern CPUs and graphics processing units(CPU) accommodate very powerful and very complex ALUs; a single component may contain a number of ALUs. Mathematician proposed the ALU concept in 1945, when he wrote a report on the foundations for a new computer called the EDVAC. (3)Memory: memory is an organism's ability to store, retain, and recall information. Traditional studies of memory...

Words: 2515 - Pages: 11

Free Essay

Sociology

...http://jozefg.ecs.fullerton.edu/public/CS906/Assignment/ |Ass # |Text Chapter |ASSIGNMENT CPSC 906 FALL 2004 |Due |Max Points | | | |Section 1 | | | | | |Note: Please provide the program assignment documentation according to | | | | | |SyllabusCS901.doc and Project Submittals.doc. | | | |1 |Ch1 |Problems: 26 p.69. Unit conversion. |09-09 |2 | | |Ch2 |Problems: 4 p.153. Stacks separated | | | |2 |Ch2 - 3 |See the exercise assignment description below |09-21 |3 | | | | |Tue | | |3 |Ch2 |Problem: 39 p.156 - provide a Gantt chart for each case and calculate AWT,| 09-30 |3 | | | |ATT and ART. Problems 44. |Thu | | | | |Provide the solution in the PowerPoint slides...

Words: 5471 - Pages: 22

Free Essay

Lua 5.0 Reference Manual

...Lua 5.0 Reference Manual Last revised on November 25, 2003 Lua Copyright c 2003 Tecgraf, PUC-Rio. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Copies of this manual can be obtained at Lua’s official web site, www.lua.org. The Lua logo was designed by A. Nakonechny. Copyright c 1998. All rights reserved. Lua 5.0 Reference Manual Roberto Ierusalimschy Luiz Henrique de Figueiredo Waldemar Celes lua@tecgraf.puc-rio.br Tecgraf — Computer Science Department — PUC-Rio PUC-RioInf...

Words: 20820 - Pages: 84

Free Essay

Competency Matrix

...Computer Science 2n (Level 0) n2 (Level 1) n (Level 2) log(n) (Level 3) data structures Doesn’t know the difference between Array and LinkedList Able to explain and use Arrays, LinkedLists, Dictionaries etc in practical programming tasks Knows space and time tradeoffs of the basic data structures, Arrays vs LinkedLists, Able to explain how hashtables can be implemented and can handle collisions, Priority queues and ways to implement them etc. Knowledge of advanced data structures like B-trees, binomial and fibonacci heaps, AVL/Red Black trees, Splay Trees, Skip Lists, tries etc. algorithms Unable to find the average of numbers in an array (It’s hard to believe but I’ve interviewed such candidates) Basic sorting, searching and data structure traversal and retrieval algorithms Tree, Graph, simple greedy and divide and conquer algorithms, is able to understand the relevance of the levels of this matrix. systems programming Doesn’t know what a compiler, linker or interpreter is Basic understanding of compilers, linker and interpreters. Understands Understands kernel mode vs. user mode, multi-threading, synchronization primitives and how they’re implemented, able to read what assembly code is and how things work at the hardware level. Some assembly code. Understands how networks work, understanding of network protocols and socket level programming. knowledge of virtual memory and paging. Able to recognize and code dynamic...

Words: 1812 - Pages: 8

Premium Essay

Saylor

...[Note: This document has been modified from the original by the Saylor Foundation] Introduction to Software History by Cornelis Robat, Editor First Steps This part will be different from the History of the computer, no chronological travel through software-land, but a collection of articles and assays on software. Software has a long history and as far as the facts are known to us we will give them to you. When missing stories, data, or other information are shared to us they will be put on this site. If you have any comments of suggestions regarding this page or any other page please do not hesitate to contact us. A simple question: "What is software?" A very simple answer is: Hardware you can touch, software you can't. But that is too simple indeed. Source URL: http://www.thocp.net/software/software_reference/introduction_to_software_history.htm Saylor URL: http://www.saylor.org/courses/cs101/ Attributed to: The History of Computing Project www.saylor.org Page 1 of 23 But when talking about software you talk about programming and programming languages. But about producing and selling the products made by programming (languages) as well. There are over 300 different ("common") computer languages in existence, apart from the various dialects stemming from one of them. Most of them can be classified in definable groups, but others don’t belong to anything. Some because they are rather new or the use of them was or is never wide spread and only used by a small specialized...

Words: 5456 - Pages: 22

Premium Essay

Learn C Programming Language in 24 Hours

...Yourself C in 24 Hours Previous | Table of Contents | Next Hour 1 - Getting Started A journey of a thousand miles is started by taking the first step. —Chinese proverb High thoughts must have high language. —Aristophanes Welcome to Teach Yourself C in 24 Hours. In this first lesson you'll learn the following:     What C is Why you need to learn C The ANSI standard Hardware and software required in order to run the C program What Is C? C is a programming language. The C language was first developed in 1972 by Dennis Ritchie at AT&T Bell Labs. Ritchie called his newly developed language C simply because there was a B programming language already. (As a matter of fact, the B language led to the development of C.) C is a high-level programming language. In fact, C is one of the most popular general-purpose programming languages. In the computer world, the further a programming language is from the computer architecture, the higher the language's level. You can imagine that the lowest-level languages are machine languages that computers understand directly. The high-level programming languages, on the other hand, are closer to our human languages. (See Figure 1.1.) Figure 1.1. The language spectrum. High-level programming languages, including C, have the following advantages:    Readability: Programs are easy to read. Maintainability: Programs are easy to maintain. Portability: Programs are easy to port across different computer platforms. The C language's...

Words: 73255 - Pages: 294

Free Essay

C Programming

...Welcome to CS 241 Systems Programming at Illinois Robin Kravets Copyright ©: University of Illinois CS 241 Staff 1 The Team  Robin Kravets    TAs   Office: 3114 SC rhk@illinois.edu Wade Fagen, Farhana Ashraf, Hilfi Alkaff and Mainak Ghosh Discussion Sections   8 sessions (Thursdays 9, 10, 11, 12, 1, 2, 3, 4) All sections in SC 0220 Copyright ©: University of Illinois CS 241 Staff 2 News and Email  Announcements and discussions: Piazza  http://www.piazza.com/illinois/cs241     All class questions This is your one-stop help-line! Will get answer < 24 hours e-mail   cs241help-fa12@cs.illinois.edu Personal questions not postable on the news group Copyright ©: University of Illinois CS 241 Staff 3 The Textbook  Introduction to Systems Concepts and Systems Programming      University of Illinois Custom Edition Copyright © 2007 Pearson Custom Publishing ISBN 0-536-48928-9 Taken from:    Operating Systems: Internals and Design Principles, Fifth Edition, by William Stallings UNIX™ Systems Programming: Communication, Concurrency, and Threads, by Kay A. Robbins and Steven Robbins Computer Systems: A Programmer's Perspective, by Randal E. Bryant and David R. O'Hallaron Copyright ©: University of Illinois CS 241 Staff 4 Your CS 241 “Mission”  Come to class     Read textbook    20% 7:00 – 9:00 PM October 15th Final  3% 47% Longer MPs are worth a little more Midterm   Reading assignments posted on webpage Homework...

Words: 1748 - Pages: 7

Free Essay

Oops

...for much more then ten years. At the core, there is little more to it then finally applying the good programming principles which we have been taught for more then twenty years. C++ (Eiffel, Oberon-2, Smalltalk ... take your pick) is the New Language because it is object-oriented — although you need not use it that way if you do not want to (or know how to), and it turns out that you can do just as well with plain ANSI-C. Only object-orientation permits code reuse between projects — although the idea of subroutines is as old as computers and good programmers always carried their toolkits and libraries with them. This book is not going to praise object-oriented programming or condemn the Old Way. We are simply going to use ANSI-C to discover how object-oriented programming is done, what its techniques are, why they help us solve bigger problems, and how we harness generality and program to catch mistakes earlier. Along the way we encounter all the jargon — classes, inheritance, instances, linkage, methods, objects, polymorphisms, and more — but we take it out of the realm of magic and see how it translates into the things we have known and done all along. I had fun discovering that ANSI-C is a full-scale object-oriented language. To share this fun you need to be reasonably fluent in ANSI-C to begin with — feeling comfortable with structures, pointers, prototypes, and function pointers is a must. Working through the book you will encounter all the newspeak — according...

Words: 72330 - Pages: 290