logo

Const modifier in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int n = 50, m = 60; const int * number_of_elements = &n; number_of_elements = &m; // valid *number_of_elements = 15; // invalid - will give compile error int * const number_of_elements2 = &n; number_of_elements2 = &m; // invalid - will give compile error *number_of_elements2 = 15; // valid return 0; }

Courses with this lesson