ok this is a weird one

10 Mar 2018 | | C

“Ok…this is a weird one…”

There are no strings in C

There is no string type in C. They are defined as an array of characters. The difference between a string and a character array is that a string has the special character ‘\0’ in it’s last position.

Example program defining and using a string as a parameter

#include<stdio.h>
 
int main()
{   
    // declaring string
    char str[50];
     
    // reading string
    scanf("%s",str);     // look ma no &str!
     
    // print string
    printf("%s",str);
 
    return 0;
}

C the Weird Parts Book : the scanf function takes a pointer to its parameter, but in the code above an ‘&’ which defines a pointer is not required, because a string is an array, and the variable str without the brackets [] represents the base address of the string array. Weird.

comments powered by Disqus(comments off)

Older · View Archive (32)

low-rider

“All my friends drive a low rider And a low rider is a little lower… “ American funk band War

Newer

is rails still viable?

… nobody ever changes their fucking mind about anything…

DHH rubyconference keynote 2017

DHH keynote talk