Skip to content

Instantly share code, notes, and snippets.

@nisanthchunduru
Last active May 17, 2023 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisanthchunduru/f1c770ca048f5fc15b7c04b0e3e19e06 to your computer and use it in GitHub Desktop.
Save nisanthchunduru/f1c770ca048f5fc15b7c04b0e3e19e06 to your computer and use it in GitHub Desktop.
Teach web dev

Structs & functions

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

int stringsTotalLength(char* firstString, char* secondString) {
  int totalLength = strlen(firstString) + strlen(secondString);
  return totalLength;
}

struct Person {
  char firstName[100];
  char lastName[100];
  int age;
};

int personNameLength(struct Person person) {
  return totalLengthOfStrings(person.firstName, person.lastName);
}

int didPersonOnlyProvideLastNameInitials(struct Person person) {
  return (strlen(person.lastName) <= 3);
}

int main(void) {
  // char firstName[] = "Suresh";
  // char lastName[] = "Borra";
  // int age = 31;

  struct Person person1 = {
    "Suresh",
    "B",
    31
  };
  
  // int nameLength = stringsTotalLength(person1.firstName, person1.lastName);
  int nameLength = personNameLength(person1);

  printf("Name length is %d\n", nameLength);

  if (didPersonOnlyProvideLastNameInitials(person1)) {
    printf("Person has only provided their last name initials");
  }

  return 0;
}

Classes, properties, functions and methods

class Person {
  constructor(firstName, lastName, age, father) {
      this.firstName = firstName;
      this.lastName = lastName,
      this.age = age;
      this.father = father;
  }

  isMinor() {
      return (this.age < 18);
  }
}

function isPersonMinor(person) {
  return (person.age < 18);
}


father = new Person("Venkata Raju", "Borra", "60", null);
son = new Person("Suresh", "Borra", 31, father);
console.log(son.firstName);
console.log(son.lastName);
console.log(son.father.firstName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment