Home > Backend Development > C++ > Interesting facts about C programming

Interesting facts about C programming

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-06 12:41:05
forward
1452 people have browsed it

Interesting facts about C programming

Here we will see some interesting facts about C programming. As follows.

  • Sometimes the case labels of some switch statements can be placed inside if-else statements.

Example
#include <stdio.h>
main() {
   int x = 2, y = 2;
   switch(x) {
      case 1:
         ;
         if (y==5) {
            case 2:
               printf("Hello World");
         }
         else case 3: {
            //case 3 block
         }
   }
}
Copy after login

Output

Hello World
Copy after login
  • Array[index] can be written as index[array]. The reason is that array elements are accessed using pointer arithmetic. The value of array[5] is *(array 5). If the order is reversed like 5[array] then it's the same as *(5 array).

Example

#include <stdio.h>
main() {
   int array[10] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 110};
   printf("array[5]: %d</p><p>", array[5]);
   printf("5[array]: %d</p><p>", 5[array]);
}
Copy after login

Output

array[5]: 66
5[array]: 66
Copy after login
  • We can use <: , :> instead of square brackets [,] and <%, %> instead of big brackets{,}.
  • ul>

    Example

    #include <stdio.h>
    main() <%
    int array<:10:> = <%11, 22, 33, 44, 55, 66, 77, 88, 99, 110%>;
    printf("array[5]: %d</p><p>", array<:5:>);
    %>
    Copy after login

    Output

    array[5]: 66
    Copy after login
    • We can use #include in some weird places. Here let us consider the file abc.txt which contains the line "The Quick Brown Fox Jumps Over The Lazy Dog". If we include the file after the printf statement, we can print the file contents.

    Example

    #include <stdio.h>
    main() {
       printf
       #include "abc.txt" ;
    }
    Copy after login

    Output

    The Quick Brown Fox Jumps Over The Lazy Dog
    Copy after login
    • We can use %*d in scanf() to ignore the input.

    Example

    #include <stdio.h>
    main() {
       int x;
       printf("Enter two numbers: ");
          scanf("%*d%d", &x);
       printf("The first one is not taken, the x is: %d", x);
    
    }
    Copy after login

    Output

    Enter two numbers: 56 69
    The first one is not taken, the x is: 69
    Copy after login

    The above is the detailed content of Interesting facts about C programming. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template