0

how can char specified as s run without &s in scanf (also run with & and also without &)

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() 
{
    char ch;
    scanf("%c", &ch);
    printf("%c\n", ch);
    char s[100];
    scanf("%s",s);
    printf("%s\n",s);
    char st[100];
    scanf("\n");
    scanf("%[^\n]%*c", st);
    printf("%s",st);    
    return 0;
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Arrays automatically decay to a pointer to the first element when used as function arguments. – Barmar Jan 18 '23 at 17:00
  • Because `s` is an array, so when passed as an argument to a function, it's equivalent to passing `&s[0]`. So it is, in fact, passing an address. – Tom Karzes Jan 18 '23 at 17:02

0 Answers0