Why does the output in the C code start counting an array index from the number 1 and not 0? -


so i've got string in c code got book has quote in it, followed string has 1 word quote. when tell program find position of substring, starts counting number 1 , not 0. why this? here mean:

#include <stdio.h> #include <string.h>  int main() {     char str[]="no time present";     char sub[]="time";     if (strstr(str, sub)== null)     {         printf("not found");     }     else     {         printf("index number found @ %d",strstr(str,sub)-str);     }     return 0 } 

so it'll say: index found @ number 3

but shouldn't printing index found @ number 2, because start zero? or can start number 1??!

yes starts @ 0, space counted character here output 3 , not 2.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -