0
#include<stdio.h>
#include<stdlib.h>

typedef struct node {
  int data;
  struct node* left, *right;
}  node;

node* createNode(int data) {
  node* x = (node*) malloc(sizeof(node));
  x->data = data;
  x->left = x->right = NULL;
  return x;
}

node * addNode(node* head, int data) {
  if (head == NULL)
    return createNode(data);

  node* temp = head;
  while (temp->right)
    temp = temp->right;

  temp->right = createNode(data);
  temp->right->left = temp;
  return head;
}

void printList(node* head) {
  node* temp = head;
  while (temp) {
    printf("%d ", temp-> data);
    temp = temp->right;
  }
}

int main() {

  node* head = NULL;
  for (int i = 0; i < 010; i++)
    head = addNode(head, i + 1);
  printList(head);
  return 0;
}

The following code produces output 1 2 3 4 5 6 7 8

I am not able to understand the working of for loop.I only wanted to check how the compiler would handle the leading zeroes while comparing.If I put more zeroes in the front , I get more nodes appended to the linked list.The number of nodes appended are always in power of two. Thanks in advance.

selbie
  • 100,020
  • 15
  • 103
  • 173

1 Answers1

1

C doesn't have binary integer literals.

Integer literals staring with a zero are octal numbers.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621