C Snippets

November 12, 2025 · View on GitHub

This extension provides a simple set of VSCode snippets for the C programming language. Can be found here on the Visual Studio Marketplace.

Visual Studio Marketplace Rating (Stars) Visual Studio Marketplace Installs Visual Studio Marketplace Downloads GitHub package.json version GitHub repo size GitHub

List of snippets:

Snippet DescriptionSnippet InputSnippet Code
Starter Templatesst#include <stdio.h>
int main (int argc, char *argv[]) {
   return 0;
}
Starter template with stlib.hlibsst#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
   return 0;
}
Conditionals and loops
If statementifif (expression) {
   /* code here */
}
Else if statementelifelseif (expression) {
   /* code here */
}
Else statementelseelse {
   /* code here */
}
For loopforfor (int i = 0; i < count; i++) {
   /* code here */
}
While loopwhilewhile (expression) {
   /* code here */
}
Do...while loopdowhiledo {
   /* code here */
} while (expression)
Header file include guardig#ifndef {transformed_file_name}
#define {transformed_file_name}

// Code for header body

#endif {transformed_file_name}
Linked lists
Linked list templateclisttypedef struct _node * Link;
typedef struct _node node;
struct _node {
   int value;
   Link next;
};
Functions
Create int functionintfuncint func_name () {
   int x;
   return x;
}
Create float functionflfuncfloat func_name () {
   float x;
   return x;
}
Create string functionstrfuncchar[] func_name () {
   char[] x = {};
   return x;
}
Create long functionlongfunclong func_name () {
   long x;
   return x;
}
Create definition for virtual tablevtdeftypedef struct {ClassName}{
struct {ClassNameVT}* vt;
};

typedef struct {ClassNameVT}
{
// Virtual Table Function definitions
} ${virtualTable Name};

int {ClassNameInit}(struct {ClassName} *self);
int {ClassNameDestroy}(struct {ClassName} **self);
Create function for virtual tablevtfunc{ReturnType} (*{FunctionName})(struct {ClassName} *self)
Print statements
Print variable of type float (2 decimal places)pfloprintf("var_name :>> %.2f\n", var_name);
Print variable of type intpintprintf("var_name :>> %d\n", var_name);
Print variable of type charpchaprintf("var_name :>> %c\n", var_name);
Print variable of type pointerppointprintf("var_name :>> %p\n", (void *) var_name);
Print variable of type size_tpsizprintf("var_name :>> %zu\n", var_name);
Memory Allocation
Allocate memory using calloccal{type} ptr = ({type})calloc(, sizeof({type}));
if (ptr == NULL) {
   printf("Memory allocation failed!\n");
   exit(0);
}
free(ptr);

Contributors: Harry Ross and Luca Merzetti