Some shorthand code methods

Source: Internet
Author: User

One: "+ +", "--" operation in the judgment and other statements directly used will reduce the code length: Example 1: The following squeeze (s,c) function, which deletes the string s appears to be all characters c:void squeeze (char s[],int c) {int i,j;       for (i=j=0;s[i]! = ' s[i '; i++) {if (s[i]! = c) {s[j++] =); }} S[j] = ' + ';}
Where the If statement is simplified by the following if statement: if (s[i]! = c) {S[j] = s[i]; j + +;}
Three: Define # define with a macro: #define MAX (A, B) ((a) > A):(B)); #define MIN (a) (a) < (b) ( A):(B)); This reduces the amount of time the program runs by eliminating the need to use functions to implement max,min, reducing the CPU used to invoke functions. Four: Perform operations in return without extra code in the body of the function, making the code look simpler! The example will not be used, ha.


This article is from "Narcissus" blog, please make sure to keep this source http://10704527.blog.51cto.com/10694527/1704937

Some shorthand code methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.