`

C basic cheat sheet

    博客分类:
  • PSP
阅读更多

Basic C Reference

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();

1) There is no space between the - and -, it’s like that to stop it appearing as –
2) There is no space between the < and =, it’s like that to stop it appearing as ⇐
分享到:
评论

相关推荐

    PowerShell Basic Cheat Sheet-计算机科学

    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

    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

    ### Shell Cheat Sheet: Essential Commands and Constructs #### File Manipulation - **Create or Overwrite a File**: Use `&gt;` to create a new file or overwrite an existing one. For example, `&gt; myfile.txt...

    python-cheat-sheet-basic.pdf

    这份"python-cheat-sheet-basic.pdf"是一个Python基础知识的速查表,涵盖了读取文件、字符串操作、数值类型与数学运算以及列表操作等多个核心概念。 首先,文件操作在Python中是通过内置的`open()`函数实现的。例如...

    XSS-Cheat-Sheet-2020-Edition.pdf

    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.5-Visual-Cheat-Sheet (PDF)

    ### jQuery 1.5 Visual Cheat Sheet详解 #### 一、概述 `jQuery-1.5-Visual-Cheat-Sheet (PDF)` 是一个针对 jQuery 1.5 版本的快速参考指南,它以 PDF 格式提供了一系列常用的选择器和其他功能的可视化表示。这份...

    jQuery 1.2 Cheat Sheet

    ### jQuery 1.2 Cheat Sheet知识点详解 #### 核心(Core) **$() The jQuery Function:** - **jQuery(expr, context):** 该方法用于在指定的上下文中选择元素。`expr` 参数定义了要匹配的选择器字符串,而 `...

    jquery.cheatsheet.1.4.pdf

    ### jQuery Cheat Sheet 1.4:详尽解析与应用指南 #### 核心概念与功能 **jQuery** 是一个快速、简洁的 JavaScript 库,它极大地简化了 HTML 文档遍历、事件处理、动画以及 Ajax 交互等操作,使得 JavaScript 的...

    xhtml_1.1_cheatsheet_v3.pdf

    ### XHTML 1.1 Cheat Sheet V3 知识点概览 #### 一、文档概述 XHTML(可扩展超文本标记语言)1.1 是一种基于 XML 的 HTML 标准,它结合了 HTML 与 XML 的优势。XHTML 1.1 的目标是提供一种更为严谨且结构化的 HTML ...

    react-pt:葡萄牙语中的 React Typescript Cheatsheet :Brazil:

    Basic Cheatsheet ( ) 专注于帮助 React 开发人员通过 React应用程序开始使用 TS 通过复制和粘贴示例专注于最佳实践。 在此过程中解释了一些基本类型的 TS 使用和配置。 回答最常见的问题。 它没有详细介绍泛型...

    cheatsheet:包装的用途(一行,标题大小写)

    备忘单备忘单的目标是...安装您可以使用以下方法从安装发布的备忘单版本: install.packages( " cheatsheet " )例子这是一个基本示例,向您展示如何解决一个常见问题: library( cheatsheet )# # basic example code

    express_cheatsheet

    1_basic_request_handling 概述如何创建端点来处理GET,POST,PUT和DELETE请求。 运行node 1_basic_request_handling.js并使用1_basic_request_handling.http测试端点。2_中间件内置,第三方和自定义中间件功能的...

    速查表-linux

    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...

    VS的TFS源码管理工具讲解

    8. **分支和合并指南 - 基本分支计划速查表** (Branching and Merging Guide - Cheatsheet Basic Branch Plan.pdf):介绍基础的分支策略,适合初学者或小型团队。 9. **分支和合并指南 - 标准分支计划速查表** ...

    HTML-Tags-Cheat-Sheet:这是针对Web开发人员HTML参考速查表

    HTML表格阅读表该项目旨在提供HTML表单的标签参考速查表,以帮助其用户在需要时可以参考,以在其网站上构建良好的表单。演示版该项目托管在GitHub页面上。 这是的链接。技术领域HTML5 CSS3 JavaScript

    CS229-Linear Algebra Review and Reference

    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...

    DeepLearning_deeplearning_pythonreferencep_

    5. "python-cheat-sheet-basic.pdf"、"python-cheat-sheet-intermediate.pdf":基础和进阶版的Python速查表,分别针对初学者和有一定经验的开发者,涵盖了不同水平的Python编程知识。 6. "Python_Importing_Data_...

    drf-cheat-sheet:Django REST Framework的备忘单快速参考指南

    这个"drf-cheat-sheet"是一个实用的快速参考指南,帮助开发者快速掌握DRF的关键概念和用法。让我们深入探讨一下这个备忘单可能包含的一些核心知识点。 1. **DRF简介**: Django REST Framework是一个高级且灵活的...

    bs4Dash:使用AdminLTE3的Bootstrap 4 Shinydashboard

    bs4Dash 使用Bootstrap 4 新用户迁移至bs4Dash v... dashboardHeader( title = " Basic dashboard " ), dashboardSidebar(), dashboardBody( # Boxes need to be put in a row (or column) fluidRow( box(plo

Global site tag (gtag.js) - Google Analytics