search
HomeBackend DevelopmentC#.Net TutorialChapter 1 C++: Function return values, GNU compiler commands

Function return value

  • The return value type must be the same as the return type of the function

  • For the main function, the return value must be of type int. On most systems, the return value of the main function is a status indicator. A return value of 0 indicates that the main function has been executed successfully; a return value of non-zero indicates that an error occurred.

GNU compiler commands

  • vi: New file, i: Edit; Esc Exit editing; wq/ZZ: Save and exit

  • g XX.cc -o XX: Compile XX.cc and generate executable file XX.

    ./XX: Run the executable file XX

  • echo $?: After executing the program, access the return value of the main function to obtain the status.

Input and output iostream

iostream library, input stream (istream) and output stream (ostream)

  • Standard input: cin

  • Standard output: cout

  • cerr: Standard error, used to output program warning and error messages.

  • clog: used to generate general information about program execution.


1. Preprocessing instructions: #include

2. Write to stream

  • Output operator :

  • Manipulator (manipulator) endl: writes it to the output stream, has the effect of line wrapping output, and refreshes the buffer associated with the device so that the user can view it immediately to write the output to the stream.

3. Use the names in the standard library, such as std::cout, std::endle

  • means that cout and endl are defined in Namespace(namespace)

  • Scope operator (scope operator, ::operator)

4. Read the stream, such as std::cin >> v1 >> v2;

  • Input operator:>>

5. Comments

  • Comment delimiters (/**/) cannot be nested

  • Best when commenting code snippets Use single-line comments (//)

Read an unknown number of inputs

  • Sum a set of numbers specified by the user and keep reading Take until the end of input.

int val;//read until end-of-file*/while(std::cin >> val)
{    ......}
  • Use the istream object as the condition, and the result is the status of the test stream. If the stream is valid, the test succeeds; if an end-of-file is encountered or the input is invalid (if the read is not an integer value, the istream object is invalid), the test will fail. .

  • Enter the file end character from the keyboard: the file end character Ctrl D in Unix, which is equivalent to (Ctrl Z Enter)*2 in the .c file of vc in Windows. Note: EOF is not required in the code.

  • The variables defined in the for loop can only exist in the for loop and cannot be used after the loop ends.

  • "Edit-Compile-Debug", after correcting an error or a small part of the error, recompile the code immediately.

Class

  • Standard library header files are enclosed in angle brackets , and non-standard library header files are enclosed in double quotes.” "Bracket it.

  • Member function, also known as class method. To call member functions, use the dot operator (.).

  • Call operator: ().

Using file redirection

$ addaItems <infile> outfile
  • The addition program has been compiled into an executable file for addItems. The above command will read from a file named infile Read the records and output the results to a file named outfile.

Terms

  • argument(actual parameter): The value passed to the called function

  • block (block) : sequence of statements enclosed in curly braces

  • main function (main function) : execution C program, the function called by the operating system. Each program has and has only one main function main

  • manipulator (manipulator) : "Manipulate" the object of the stream itself when reading or writing, such as std: :ebndl.

  • member function (member function), method (method) : synonyms, referring to the operations defined by the class

  • Namespace (namespace): A mechanism to put the names defined by the library into a single place. Namespaces help avoid unintentional naming conflicts. Names defined by the C standard library are in the namespace std.

  • string literal : A sequence of characters enclosed in double quotes

  • Uninitialized variable (uninitialized variable) : If the class type does not specify an initial value, it will be initialized according to the class definition. Built-in type variables defined inside a function are not initialized by default unless there is an explicit initialization statement.

Reference: C Primer Fifth Edition

Related articles:

Chapter 2 C: Variables and Basic Types

Chapter 3 C: string string, vector vector and array

The above is the detailed content of Chapter 1 C++: Function return values, GNU compiler commands. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Mastering C# .NET Design Patterns: From Singleton to Dependency InjectionMastering C# .NET Design Patterns: From Singleton to Dependency InjectionMay 09, 2025 am 12:15 AM

Design patterns in C#.NET include Singleton patterns and dependency injection. 1.Singleton mode ensures that there is only one instance of the class, which is suitable for scenarios where global access points are required, but attention should be paid to thread safety and abuse issues. 2. Dependency injection improves code flexibility and testability by injecting dependencies. It is often used for constructor injection, but it is necessary to avoid excessive use to increase complexity.

C# .NET in the Modern World: Applications and IndustriesC# .NET in the Modern World: Applications and IndustriesMay 08, 2025 am 12:08 AM

C#.NET is widely used in the modern world in the fields of game development, financial services, the Internet of Things and cloud computing. 1) In game development, use C# to program through the Unity engine. 2) In the field of financial services, C#.NET is used to develop high-performance trading systems and data analysis tools. 3) In terms of IoT and cloud computing, C#.NET provides support through Azure services to develop device control logic and data processing.

C# .NET Framework vs. .NET Core/5/6: What's the Difference?C# .NET Framework vs. .NET Core/5/6: What's the Difference?May 07, 2025 am 12:06 AM

.NETFrameworkisWindows-centric,while.NETCore/5/6supportscross-platformdevelopment.1).NETFramework,since2002,isidealforWindowsapplicationsbutlimitedincross-platformcapabilities.2).NETCore,from2016,anditsevolutions(.NET5/6)offerbetterperformance,cross-

The Community of C# .NET Developers: Resources and SupportThe Community of C# .NET Developers: Resources and SupportMay 06, 2025 am 12:11 AM

The C#.NET developer community provides rich resources and support, including: 1. Microsoft's official documents, 2. Community forums such as StackOverflow and Reddit, and 3. Open source projects on GitHub. These resources help developers improve their programming skills from basic learning to advanced applications.

The C# .NET Advantage: Features, Benefits, and Use CasesThe C# .NET Advantage: Features, Benefits, and Use CasesMay 05, 2025 am 12:01 AM

The advantages of C#.NET include: 1) Language features, such as asynchronous programming simplifies development; 2) Performance and reliability, improving efficiency through JIT compilation and garbage collection mechanisms; 3) Cross-platform support, .NETCore expands application scenarios; 4) A wide range of practical applications, with outstanding performance from the Web to desktop and game development.

Is C# Always Associated with .NET? Exploring AlternativesIs C# Always Associated with .NET? Exploring AlternativesMay 04, 2025 am 12:06 AM

C# is not always tied to .NET. 1) C# can run in the Mono runtime environment and is suitable for Linux and macOS. 2) In the Unity game engine, C# is used for scripting and does not rely on the .NET framework. 3) C# can also be used for embedded system development, such as .NETMicroFramework.

The .NET Ecosystem: C#'s Role and BeyondThe .NET Ecosystem: C#'s Role and BeyondMay 03, 2025 am 12:04 AM

C# plays a core role in the .NET ecosystem and is the preferred language for developers. 1) C# provides efficient and easy-to-use programming methods, combining the advantages of C, C and Java. 2) Execute through .NET runtime (CLR) to ensure efficient cross-platform operation. 3) C# supports basic to advanced usage, such as LINQ and asynchronous programming. 4) Optimization and best practices include using StringBuilder and asynchronous programming to improve performance and maintainability.

C# as a .NET Language: The Foundation of the EcosystemC# as a .NET Language: The Foundation of the EcosystemMay 02, 2025 am 12:01 AM

C# is a programming language released by Microsoft in 2000, aiming to combine the power of C and the simplicity of Java. 1.C# is a type-safe, object-oriented programming language that supports encapsulation, inheritance and polymorphism. 2. The compilation process of C# converts the code into an intermediate language (IL), and then compiles it into machine code execution in the .NET runtime environment (CLR). 3. The basic usage of C# includes variable declarations, control flows and function definitions, while advanced usages cover asynchronous programming, LINQ and delegates, etc. 4. Common errors include type mismatch and null reference exceptions, which can be debugged through debugger, exception handling and logging. 5. Performance optimization suggestions include the use of LINQ, asynchronous programming, and improving code readability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!