Basic C Reference
Here you’ll find some of the basic operators and variable types used in C with quick examples. Please note this section is not complete as things like pointers and structures aren’t listed and some of the code examples could be improved. Also missing is the const keyword, some logical operators and conversion specify -ers.
Basic Operators
Operator Explanation
== | This means that for example, a == b, then a is equal to or equals b |
!= | This means, in the example a != b, a does not equal b |
+= | This operator is an easy way to add a value to a variable, a += 5, this increases a by 5 |
-= | This operator as the above, does the opposite, a -= 5, will decrease a by 5 |
++ | This operator is used to add 1 to a variable, a++, would increase a by 1 |
- - | This is the above operators opposite, meaning a- -, would decrease a by 1 1) |
> | The greater than operator |
< | The less than operator |
>= | The greater than or equal to operator |
< = | The less than or equal to operator 2) |
Basic Syntax and Correct Usage
/* ... */
Multiple line comments can be placed within these as the C compiler will skip all text and or code between them until it reaches a close comment.
//
Single line comment allowing you to comment out a line of code or add a quick comment. The comment must be all on one line.
#include <lib.h>
Includes the header file ‘lib.h’. This allows you to use all the data types and functions declared in lib.h. The included file can a standard C library file like stdio.h or a PSP one like pspkernel.h. You can also include your own header files. When the file is in another folder you include it like so:
#include "headerFile.h"
#define TRUE 1
Defines a macro to replace all occurrences of TRUE with 1, when compiled. The benefit of having this as a #define is that it makes you code much more readable and understandable. Also if the value of TRUE needs to change you only have to do it once rather than for each time it is used.
It can also allow you to define new function names for existing functions. You can also define macro functions.
// Use printf instead of pspDebugScreenPrintf
#define printf pspDebugScreenPrintf
// Returns the larger of the two values
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
void
The void type specifier is primarily used to declare void functions - functions that do not return values. Please note that main() must return an int otherwise it will cause a warning since the program has to return something with the new ISO standards.
int
Used to declare a new variable of type int, to specify the return value type of a function or the type of input for a function.
Pre-fix for returning a whole number variable (ex: int pi = 3).
float
Used to declare a new variable of type float, to specify the return value type of a function or the type of input for a function.
Pre-fix for returning either a whole or decimal integer (ex: float pi = 3.14)
char
Pre-fix for a single character. It can be used as a string, an array, or a buffer. To define a string in C you have to create an array of char’s as there is no string type in C.
char myChar = 'a';
char myString[32] = "abcde";
The string example above is for a fixed length string of 32 characters. One character is left for a terminating NULL character - \0 - so the string’ actual length is 31.
{ ... }
These are braces, they signal the beginning and end of functions and other code blocks such as loops and if statements.
;
The semi-colon is used to distinguish the EOL, with the exception of after multi-line arguments and do while loops, where the semi-colon appears after the while keyword and condition.
do {
...
}
while();
分享到:
相关推荐
Pass objects Get-process word | Stop-ProcessCtrl+c Interrupt current commandLeft/right Navigate editing cursorCtrl+left/right Navigate a word at a timeHome / End Move to start / end of lineUp/down ...
data wrangling cheatsheet It provides some basic code for you. It will be convenient for you to reference, especially when you are new to data wrangling
### Shell Cheat Sheet: Essential Commands and Constructs #### File Manipulation - **Create or Overwrite a File**: Use `>` to create a new file or overwrite an existing one. For example, `> myfile.txt...
这份"python-cheat-sheet-basic.pdf"是一个Python基础知识的速查表,涵盖了读取文件、字符串操作、数值类型与数学运算以及列表操作等多个核心概念。 首先,文件操作在Python中是通过内置的`open()`函数实现的。例如...
This cheat sheet is meant to be used by bug hunters, penetration testers, security analysts, web application security students and enthusiasts. It’s about Cross-Site Scripting (XSS), the most ...
### jQuery 1.2 Cheat Sheet知识点详解 #### 核心(Core) **$() The jQuery Function:** - **jQuery(expr, context):** 该方法用于在指定的上下文中选择元素。`expr` 参数定义了要匹配的选择器字符串,而 `...
### jQuery Cheat Sheet 1.4:详尽解析与应用指南 #### 核心概念与功能 **jQuery** 是一个快速、简洁的 JavaScript 库,它极大地简化了 HTML 文档遍历、事件处理、动画以及 Ajax 交互等操作,使得 JavaScript 的...
### XHTML 1.1 Cheat Sheet V3 知识点概览 #### 一、文档概述 XHTML(可扩展超文本标记语言)1.1 是一种基于 XML 的 HTML 标准,它结合了 HTML 与 XML 的优势。XHTML 1.1 的目标是提供一种更为严谨且结构化的 HTML ...
Basic Cheatsheet ( ) 专注于帮助 React 开发人员通过 React应用程序开始使用 TS 通过复制和粘贴示例专注于最佳实践。 在此过程中解释了一些基本类型的 TS 使用和配置。 回答最常见的问题。 它没有详细介绍泛型...
备忘单备忘单的目标是...安装您可以使用以下方法从安装发布的备忘单版本: install.packages( " cheatsheet " )例子这是一个基本示例,向您展示如何解决一个常见问题: library( cheatsheet )# # basic example code
1_basic_request_handling 概述如何创建端点来处理GET,POST,PUT和DELETE请求。 运行node 1_basic_request_handling.js并使用1_basic_request_handling.http测试端点。2_中间件内置,第三方和自定义中间件功能的...
10-Linux-Unix-Command-Cheat-Sheet-011.jpg 10-Linux-Unix-Command-Cheat-Sheet-021.jpg CliCommandsFull.jpg davechild_linux-command-line.pdf linux file search 305883.jpg linux-cheat-sheet-wallpapers...
8. **分支和合并指南 - 基本分支计划速查表** (Branching and Merging Guide - Cheatsheet Basic Branch Plan.pdf):介绍基础的分支策略,适合初学者或小型团队。 9. **分支和合并指南 - 标准分支计划速查表** ...
HTML表格阅读表该项目旨在提供HTML表单的标签参考速查表,以帮助其用户在需要时可以参考,以在其网站上构建良好的表单。演示版该项目托管在GitHub页面上。 这是的链接。技术领域HTML5 CSS3 JavaScript
1、Basic Concepts and Notation 2、 Matrix Multiplication 2.1 Vector-Vector Products 2.2 Matrix-Vector Products 2.3 Matrix-Matrix Products 3、Operations and Properties ...... 4、Matrix Calculus 2...
5. "python-cheat-sheet-basic.pdf"、"python-cheat-sheet-intermediate.pdf":基础和进阶版的Python速查表,分别针对初学者和有一定经验的开发者,涵盖了不同水平的Python编程知识。 6. "Python_Importing_Data_...
这个"drf-cheat-sheet"是一个实用的快速参考指南,帮助开发者快速掌握DRF的关键概念和用法。让我们深入探讨一下这个备忘单可能包含的一些核心知识点。 1. **DRF简介**: Django REST Framework是一个高级且灵活的...
bs4Dash 使用Bootstrap 4 新用户迁移至bs4Dash v... dashboardHeader( title = " Basic dashboard " ), dashboardSidebar(), dashboardBody( # Boxes need to be put in a row (or column) fluidRow( box(plo